fix(apt): remove incorrect 'new QClass()' suggestion from circular Q-class warning - #1905
Open
o54711254 wants to merge 1 commit into
Open
Conversation
…class warning
Suggestion (3) in the circular Q-class warning claimed that using
'new QClass("alias")' would avoid the initialization deadlock, but
instance creation triggers class initialization (JLS 12.4.1) just like
static field access does, so the same deadlock occurs.
Follow-up to OpenFeign#1739.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Background
In #1739 I added compile-time detection for circular Q-class references that can
cause class initialization deadlocks. The warning message suggests three
workarounds:
Suggestion (3) does not work. This PR removes it.
Why (3) does not work
Creating an instance of a class triggers class initialization (JLS 12.4.1),
exactly as accessing a static field does. So
new QOrder("alias")still runsQOrder.<clinit>, which initializes the static field, whose constructorcreates the other Q-class — the same chain that causes the deadlock.
Given a bidirectional
@OneToOnebetweenOrderandPayment, the generatedclass looks like this:
new QOrder("alias")→ triggers
QOrder.<clinit>→ initializes the static field
order→ its constructor creates
QPayment→ triggers
QPayment.<clinit>Avoiding static field access does not avoid static field initialization.
Reproduction
Two threads, each entering only via
new:Output:
Neither thread completed — both were blocked on class initialization monitors.
Change
Removes suggestion (3) from the warning message. (1) and (2) remain valid and
are unaffected. The detection logic itself is unchanged.
Follow-up to #1739. Sorry for the incorrect guidance in the original PR.