question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Compile time checks for class initialization deadlocks

See original GitHub issue

Description 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:open
  • Created 3 years ago
  • Reactions:3
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
magibneycommented, Apr 25, 2022

+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.

2reactions
carterkozakcommented, Oct 24, 2022

No worries, @cushon. I’d be happy to 😃

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found