Skip to content

Commit 1966d6d

Browse files
cushonError Prone Team
authored andcommitted
Fix an NPE in StringConcatToTextBlock
The linemap isn't available if debug info is disabled, so just skip findings in that case. PiperOrigin-RevId: 738668315
1 parent 04f05c2 commit 1966d6d

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

core/src/main/java/com/google/errorprone/bugpatterns/StringConcatToTextBlock.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,9 @@ private Description match(
173173
(s, orig) -> s + " ".repeat(orig.length() - SPACE.trimTrailingFrom(orig).length()))
174174
.collect(toImmutableList());
175175
LineMap lineMap = state.getPath().getCompilationUnit().getLineMap();
176+
if (lineMap == null) {
177+
return NO_MATCH;
178+
}
176179
String indent = " ".repeat((int) lineMap.getColumnNumber(replaceFrom) - 1);
177180
String suffix = trailingNewline ? "" : "\\";
178181
String replacement =

core/src/test/java/com/google/errorprone/bugpatterns/StringConcatToTextBlockTest.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,4 +271,19 @@ record Test(@SuppressWarnings("foo") @Anno int foo) {}
271271
.expectUnchanged()
272272
.doTest(TEXT_MATCH);
273273
}
274+
275+
@Test
276+
public void noDebug() {
277+
refactoringHelper
278+
.addInputLines(
279+
"Test.java",
280+
"""
281+
class Test {
282+
String s = "hello\\n" + "world\\n";
283+
}
284+
""")
285+
.expectUnchanged()
286+
.setArgs("-g:none")
287+
.doTest(TEXT_MATCH);
288+
}
274289
}

0 commit comments

Comments
 (0)