Compile time checks for class initialization deadlocks
See original GitHub issueDescription of the problem / feature request:
Class initialization deadlocks are common when a type uses one of its subtypes in a static field or block.
Feature requests: what underlying problem are you trying to solve with this feature?
I would like to catch these deadlocks at compile time rather than intermittently at runtime! I have implemented such a check here, but I believe it would be a good candidate for error-prone upstream:
https://github.com/palantir/gradle-baseline/pull/1598
Bugs: what’s the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.
Example from guava: https://github.com/google/guava/issues/1977
class Base {
static final Object FIELD = new Sub();
static class Sub implements Base {
}
}
What version of Error Prone are you using?
2.4.0
Have you found anything relevant by searching the web?
no
Issue Analytics
- State:
- Created 3 years ago
- Reactions:3
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Using static analysis to prevent deadlocks - Palantir Blog
Using Static Analysis to Prevent Java Class Initialization Deadlocks ... rule that bans a number of known bad static class dependencies at compile...
Read more >java - Deadlock caused by creating a new thread during class ...
When a class has not completed initialization, threads that reference the class attempt to obtain the class initialization lock. The first ...
Read more >[#LUCENE-9672] Detects deadlock occurring at static initialization ...
Deadlock can be happened when a parent class uses a child class at static initialization timing. Currently we don't check it at build...
Read more >Observing lock when loading class by two thread, is it a JVM ...
class, and in 1.4 class literals cause class initialization. So if thread 1 starts by initializing NestedThrowable, and thread 2 starts by ...
Read more >When a class is loaded and initialized in JVM - Java Example
1. Here class initialization occurs because a static field is accessed which is not a compile time constant. had you declare "familyName" compile...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
+1; this feature would have helped with https://github.com/apache/solr/pull/819 (https://issues.apache.org/jira/browse/SOLR-16165).
It’s worth mentioning @carterkozak’s subsequent blog post on the topic.
No worries, @cushon. I’d be happy to 😃