Skip to content

Conversation

@EnzeXing
Copy link
Contributor

@EnzeXing EnzeXing commented Nov 6, 2025

Calling global object methods before super constructor finishes is unsafe and may lead to java.lang.ExceptionInInitializerError (see #24201). This PR lets global object init checker gives warning for this case

@EnzeXing EnzeXing force-pushed the fix-global-init-checker-object-call branch from 3385505 to 4737d4f Compare November 7, 2025 02:52
@EnzeXing
Copy link
Contributor Author

EnzeXing commented Nov 7, 2025

@olhotak @liufengyun

@EnzeXing EnzeXing force-pushed the fix-global-init-checker-object-call branch from 4737d4f to edf760c Compare November 7, 2025 03:09
ObjectRef(classSym)
val obj = ObjectRef(classSym)
obj.setAfterSuperCall()
obj
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about obj.setAfterSuperCall here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is when we don't have source, so we're not checking this object at all. Presumably in that case it should always be OK to access the object, so setAfterSuperCall makes sense to me.

UnknownValue
else if ref.isInstanceOf[ObjectRef] && !ref.asObjectRef.isAfterSuperCall then
report.warning("Calling " + target + " of object " + ref.klass + " before the super constructor of the object finishes! " + Trace.show, Trace.position)
Bottom
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking whether the check should be moved to accessObject?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think so too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants