From bdb60eec320907a4e75d4011e5594ef884ca096b Mon Sep 17 00:00:00 2001 From: Stephan Schroevers Date: Sun, 20 Nov 2022 15:21:12 +0100 Subject: [PATCH] Tweak --- .../picnic/errorprone/bugpatterns/util/SourceCode.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) 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, + ""); } }