Test/increase test coverage#1621
Conversation
…sion containing the word "null"test
…backs and anonymous class callbacks when passed to {@code Map.forEach}.
…l} precondition inheritance violation must list the <b>extra</b> fields added by the child method, not the parent's fields.
|
|
|
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 (6)
WalkthroughThe PR makes two bug fixes with accompanying tests, plus two standalone test additions. In Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ 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 |
|
@Beluomini thanks for these contributions! For cleanliness, and to ease a narrow revert in case of some unexpected future issue, I'd prefer this be split into separate PRs; one for the SpringHandler fix (with its tests), one for the RequiresNonNullHandler fix (with its tests), and one for the remaining tests. Could you possibly do that? |
Fix false positives in SpringHandler and RequiresNonNullHandler; add tests for coverage gaps
What and why
This PR fixes two bugs found while increasing test coverage, and adds unit tests for previously
untested code paths in four handlers.
Bug fixes
1.
SpringHandler: false positive for SpEL expressions withnullin comparisonscontainsNullSpELExpressionused a single regex that matchednullanywhere inside a#{...}expression. This caused a false positive for conditional expressions like:
NullAway incorrectly flagged
fieldas potentially null, even thoughnullhere is only used ina comparison, not as a possible return value. Fix: a second regex (
NULL_COMPARISON_PATTERN) stripsnull-in-comparison occurrences before re-checking whether
nullcan actually be the value.2.
RequiresNonNullHandler: error message invalidateOverridingRuleslisted the wrong fieldsWhen a child method's
@RequiresNonNullwas stricter than its parent's (violating LSP), the errormessage listed the parent's fields instead of the extra fields added by the child. Fix: use
the correct iterator (
overridingFieldNamesinstead ofoverriddenFieldNames) when building themessage.
New tests
JakartaPersistenceTests.jakartaPersistenceMixedAccessBothMappingsIsUnknown— covers thecase where a JPA entity has both field-level and getter-level mapping annotations simultaneously,
which resolves to
UNKNOWNaccess type and causes NullAway to report uninitialized-field errors.FrameworkTests.springValueSpelWithNullInConditional,springValueSpelNullAsReturnValue,springValueSpelNullComparisonLeftSide— regressiontests for the
SpringHandlerfix, covering null-as-comparison-operand (both sides) andnull-as-return-value in SpEL expressions.
SyncLambdasTests.forEachOnMapWithAnonymousClass— documents that anonymous classes passedto
Map.forEachdo not benefit from nullness-fact propagation (unlike lambdas), because the ASTparent node is
NewClassTree, notMethodInvocationTree.EnsuresNonNullTests.requiresNonNullOverridingErrorMessageListsExtraFields— regression testfor the
RequiresNonNullHandlerfix, verifying that the error message lists[b, c](the extrafields added by the child) rather than
[a](the parent's fields) when multiple extra fieldscause the violation.
Unit tests
All four items above include unit tests. The two bug-fix items include regression tests that fail on
the unfixed code and pass after the fix.
Summary by CodeRabbit
Bug Fixes
nullare treated more accurately.Tests