From 11c842f4ef613bd2d92c7b5e8a6041260a706fb7 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 24 Apr 2026 00:34:48 +0000 Subject: [PATCH 1/2] #841: Add failing tests for NPE when +unlint range references 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. --- .../org/eolang/lints/DefectMissingTest.java | 19 ++++++++++++++++ .../lints/LtUnlintNonExistingDefectTest.java | 22 +++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/src/test/java/org/eolang/lints/DefectMissingTest.java b/src/test/java/org/eolang/lints/DefectMissingTest.java index 25f89784f..fb412dffc 100644 --- a/src/test/java/org/eolang/lints/DefectMissingTest.java +++ b/src/test/java/org/eolang/lints/DefectMissingTest.java @@ -80,4 +80,23 @@ void returnsTrueIfSomeLineIsOutOfRange() { Matchers.equalTo(true) ); } + + @Test + void returnsTrueWhenRangeReferencesAbsentLint() { + MatcherAssert.assertThat( + "Defect should be missing when referenced lint is absent from map", + new DefectMissing(new MapOf<>("other-lint", new ListOf<>(1, 2)), new ListOf<>()) + .apply("ascii-only:1-5"), + Matchers.equalTo(true) + ); + } + + @Test + void returnsTrueWhenRangeReferencesLintInEmptyMap() { + MatcherAssert.assertThat( + "Defect should be missing when defects map is empty", + new DefectMissing(new MapOf<>(), new ListOf<>()).apply("ascii-only:1-5"), + Matchers.equalTo(true) + ); + } } diff --git a/src/test/java/org/eolang/lints/LtUnlintNonExistingDefectTest.java b/src/test/java/org/eolang/lints/LtUnlintNonExistingDefectTest.java index eca2a1deb..eb4b93e87 100644 --- a/src/test/java/org/eolang/lints/LtUnlintNonExistingDefectTest.java +++ b/src/test/java/org/eolang/lints/LtUnlintNonExistingDefectTest.java @@ -222,4 +222,26 @@ void catchesUnlintWithOutOfRangeLines() throws IOException { Matchers.iterableWithSize(1) ); } + + @Test + void catchesRangeUnlintOfAbsentLint() throws IOException { + MatcherAssert.assertThat( + "Range unlint referencing an absent lint should be reported, not throw NPE", + new LtUnlintNonExistingDefect( + new ListOf<>(new LtAsciiOnly()), + new ListOf<>() + ).defects( + new EoSyntax( + String.join( + "\n", + "+unlint ascii-only:1-5", + "", + "# Hello.", + "[] > main" + ) + ).parsed() + ), + Matchers.hasSize(Matchers.greaterThan(0)) + ); + } } From 3f7fca2aaf1c7d283f1d81bd60592537b656396c Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 24 Apr 2026 00:54:29 +0000 Subject: [PATCH 2/2] #841: Fix NPE in DefectMissing for range unlint of absent 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. --- src/main/java/org/eolang/lints/DefectMissing.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/eolang/lints/DefectMissing.java b/src/main/java/org/eolang/lints/DefectMissing.java index c6c2ed17a..f292267d2 100644 --- a/src/main/java/org/eolang/lints/DefectMissing.java +++ b/src/main/java/org/eolang/lints/DefectMissing.java @@ -44,7 +44,11 @@ public Boolean apply(final String unlint) { final String name = split[0]; final List lines = this.defects.get(name); if (unlint.matches(String.format("%s:\\d+-\\d+", name))) { - missing = !lines.stream().allMatch(new UnlintInRange(unlint)); + if (lines == null) { + missing = !this.excluded.contains(name); + } else { + missing = !lines.stream().allMatch(new UnlintInRange(unlint)); + } } else { final Set names; if (this.defects != null) {