Fix NPE in DefectMissing for range +unlint of absent lint (#841)#844
Fix NPE in DefectMissing for range +unlint of absent lint (#841)#844bibonix wants to merge 2 commits intoobjectionary:masterfrom
Conversation
…nces absent lint Reproduces the NullPointerException thrown by DefectMissing.apply() when a range-form unlint expression (name:line-line) references a lint name that is not present in the defects map.
… lint When a range-form '+unlint name:line-line' expression references a lint name that is absent from the defects map, this.defects.get(name) returns null and calling null.stream() throws NullPointerException. Treat a null lines list the same way the non-range branch does: the defect is missing unless the name is in the excluded list.
📝 WalkthroughWalkthroughThis pull request fixes a NullPointerException in DefectMissing when unlint directives use range patterns ( Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 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 |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/test/java/org/eolang/lints/DefectMissingTest.java (1)
84-101: Good coverage for the absent-key + range scenarios.Both tests correctly exercise the new
lines == nullbranch (one with other map entries, one with an empty map).Optional: consider adding a third case where the absent lint name is in the
excludedcollection, assertingapply(...)returnsfalse. That would pin down the!this.excluded.contains(name)half of the new branch, which is currently only implicitly covered.🧪 Optional additional test
+ `@Test` + void returnsFalseWhenRangeReferencesExcludedAbsentLint() { + MatcherAssert.assertThat( + "Defect should not be missing when referenced lint is excluded", + new DefectMissing(new MapOf<>(), new ListOf<>("ascii-only")) + .apply("ascii-only:1-5"), + Matchers.equalTo(false) + ); + }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/test/java/org/eolang/lints/DefectMissingTest.java` around lines 84 - 101, Add a third unit test that verifies the case where the referenced lint name is absent from the defects map but present in the excluded collection: construct a DefectMissing with an empty or non-matching MapOf for defects and a ListOf that contains the lint name in the excluded parameter, then call DefectMissing.apply("ascii-only:1-5") and assert it returns false; this will exercise the "!this.excluded.contains(name)" path in DefectMissing.apply and ensure the excluded list suppresses the missing-defect result.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@src/test/java/org/eolang/lints/DefectMissingTest.java`:
- Around line 84-101: Add a third unit test that verifies the case where the
referenced lint name is absent from the defects map but present in the excluded
collection: construct a DefectMissing with an empty or non-matching MapOf for
defects and a ListOf that contains the lint name in the excluded parameter, then
call DefectMissing.apply("ascii-only:1-5") and assert it returns false; this
will exercise the "!this.excluded.contains(name)" path in DefectMissing.apply
and ensure the excluded list suppresses the missing-defect result.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: e1958622-29a7-42c4-adc5-eddcb2ecbb2e
📒 Files selected for processing (3)
src/main/java/org/eolang/lints/DefectMissing.javasrc/test/java/org/eolang/lints/DefectMissingTest.javasrc/test/java/org/eolang/lints/LtUnlintNonExistingDefectTest.java
|
Closing as duplicate of #843, which was opened yesterday for the same issue and has a green CI matrix. Sorry for the noise. |
Fixes #841.
When
+unlint name:line-line(range form) references a lint name that did not fire,DefectMissing.apply()callsthis.defects.get(name)which returnsnull, and thenlines.stream()throwsNullPointerException.This PR:
DefectMissingTestcovering the missing-key + range case (with and without other entries in the map).catchesRangeUnlintOfAbsentLinttoLtUnlintNonExistingDefectTestmatching the reproducer in the issue.DefectMissing.apply()to treat anulllines list the same way the non-range branch does: the defect is reported as missing unless the lint name is in theexcludedlist.Summary by CodeRabbit
Release Notes
Bug Fixes
Tests