Repository navigation
Test requireNonNullElse inference with and without the JSpecify JDK models - #2033
Conversation
…odels With `WarnOnGenericInferenceFailure` on and no JDK models, returning `Objects.requireNonNullElse(nullable, nonNull)` from a method with a non-null `String` return reports `inference failure: type variable T constrained to be both @nonnull and @Nullable` (apache#1493). The JSpecify JDK models (apache#1641, NullAway 0.14.0) declare `<T> T requireNonNullElse(@nullable T obj, @nullable T defaultObj)`, so `T` is inferred as non-null `String` and nothing is reported. The models are enabled by `-XepOpt:NullAway:JSpecifyJDKModels=true`, or by `-XepOpt:NullAway:JSpecifyExperimental=true`, whose value that flag defaults to. `GenericMethodTests.issue1493` was added with `@Ignore` in apache#1496 and passes now. This change enables it as `issue1493RequireNonNullElseWithJdkModels` and adds `issue1493RequireNonNullElseWithoutJdkModels`, which compiles the same source with `JSpecifyJDKModels=false` and expects the inference failure. Both tests set `WarnOnGenericInferenceFailure=true` and `JSpecifyJDKModels` explicitly instead of taking them from the `JSpecifyExperimental` default, so the pair differs only in the models flag; with that flag set to `true`, the second test fails with "There were no errors". Refs apache#1493. Merging does not close it: the reporter's configuration without the models (`JSpecifyMode` plus `WarnOnGenericInferenceFailure=true`) still reports the warning, and whether the issue can close before the models are on by default is for the maintainers to decide. Assisted-by: Claude Code (claude-opus-5-5)
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
WalkthroughThe previously ignored issue 1493 test is replaced by two enabled tests for Suggested reviewers: Priority: ⬇️ Low Change: Other Merge Risk: ⚪ Minimal · up to
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #2033 +/- ##
============================================
+ Coverage 88.92% 89.13% +0.21%
Complexity 38 38
============================================
Files 118 119 +1
Lines 12601 12707 +106
Branches 2550 2580 +30
============================================
+ Hits 11206 11327 +121
+ Misses 629 623 -6
+ Partials 766 757 -9 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
With
WarnOnGenericInferenceFailureon and no JDK models, returningObjects.requireNonNullElse(nullable, nonNull)from a method with a non-nullStringreturn reportsinference failure: type variable T constrained to be both @NonNull and @Nullable(#1493). The JSpecify JDK models (#1641, NullAway 0.14.0) declare<T> T requireNonNullElse(@Nullable T obj, @Nullable T defaultObj), soTis inferred as non-nullStringand nothing is reported. The models are enabled by-XepOpt:NullAway:JSpecifyJDKModels=true, or by-XepOpt:NullAway:JSpecifyExperimental=true, whose value that flag defaults to.GenericMethodTests.issue1493was added with@Ignorein #1496 and passes now. This change enables it asissue1493RequireNonNullElseWithJdkModelsand addsissue1493RequireNonNullElseWithoutJdkModels, which compiles the same source withJSpecifyJDKModels=falseand expects the inference failure. Both tests setWarnOnGenericInferenceFailure=trueandJSpecifyJDKModelsexplicitly instead of taking them from theJSpecifyExperimentaldefault, so the pair differs only in the models flag; with that flag set totrue, the second test fails with "There were no errors".Refs #1493. Merging does not close it: the reporter's configuration without the models (
JSpecifyModeplusWarnOnGenericInferenceFailure=true) still reports the warning, and whether the issue can close before the models are on by default is for the maintainers to decide.🤖 Generated with Claude Code
Summary by CodeRabbit
Objects.requireNonNullElsegeneric inference with JSpecify JDK models enabled and disabled.