diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/util/SourceCode.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/util/SourceCode.java index ab40083198..dcdf755d3b 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/util/SourceCode.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/util/SourceCode.java @@ -53,9 +53,10 @@ public static SuggestedFix deleteWithTrailingWhitespace(Tree tree, VisitorState return SuggestedFix.delete(tree); } - int actualEnd = NON_WHITESPACE_MATCHER.indexIn(sourceCode, endPos); - return actualEnd == -1 - ? SuggestedFix.delete(tree) - : SuggestedFix.replace(((DiagnosticPosition) tree).getStartPosition(), actualEnd, ""); + int whitespaceEndPos = NON_WHITESPACE_MATCHER.indexIn(sourceCode, endPos); + return SuggestedFix.replace( + ((DiagnosticPosition) tree).getStartPosition(), + whitespaceEndPos == -1 ? sourceCode.length() : whitespaceEndPos, + ""); } }