Fix null dereference and FalseBoundException crash in type argument inference; fixes #7681#7735
Conversation
#7681 - In Typing.java reduceSubtypeClass(), null-check the result of asSuper() before calling capture() on it. - In InvocationTypeInference.java getB4(), catch FalseBoundException from reduceAdditionalArgOnce() and continue gracefully.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThis PR: (1) guards against a null dereference in Typing.reduceSubtypeClass by checking asSuper before capture, (2) wraps reduceAdditionalArgOnce in InvocationTypeInference.getB4 with a try/catch for FalseBoundException and skips failing additional-arg constraints, and (3) adds checker/tests/nullness/java8inference/Issue7681.java, a regression test exercising nested generics, lambdas, and a method reference. Possibly related issues
Suggested reviewers
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Hi @mernst, this PR fixes the two crashes reported in #7681 (NPE in Typing.java and FalseBoundException in InvocationTypeInference.java). All functional CI jobs pass (junit, inference, typecheck, nonjunit). The misc_jdk25 and misc_jdk26 failures are maybe pre-existing — ./gradlew requireJavadoc fails on upstream/master itself with the same 1189 violations, none of which were introduced by this PR. Would you be able to review? |
smillst
left a comment
There was a problem hiding this comment.
This pull request does not fix the issue. It converts it to a different exception and then ignores the exception.
|
Thank you for the review feedback @smillst. After deeper investigation, I found that the root cause is different from what the original fix addressed. What I found: The premature resolution of I happens in getB4 in InvocationTypeInference.java: I gets resolved early because it only has a proper upper bound (Object) at that point, before the lambda body constraints have had a chance to add tighter bounds. My current fix (return new ConstraintSet() when asSuper() is null in Typing.java) prevents the crash but does not produce the correct inference result — the code still fails with type.arguments.not.inferred. |
|
After further investigation, I want to suggest the potential fix direction. A possible fix would be to guard the early resolution so that a variable is not resolved if it is still an input to any pending lambda or method reference constraint in c: This way I would not be resolved until after all lambda/method reference constraints that depend on it are processed, allowing getFunctionTypeParameterTypes() to return the correct type Generic<Generic> instead of Object for the GenericConverter::passthru method reference. Would this be the right direction? And if so, what would be the correct way to implement isInputToPendingLambdaOrMethodRef? |
|
Please do not open a pull request without an understanding of the code and of your changes. That is as waste of everyone's time. (Sometimes this is a result of using AI uncritically.) |
PR Description:
error: [type.argument.inference.crashed] Type argument inference crashed
error: An exception occurred: Cannot invoke "AbstractType.capture(...)"
because the return value of "AbstractType.asSuper(...)" is null
Fixes: #7681