Skip to content

Commit 35c7777

Browse files
committed
Fix a StringIndexOutOfBoundsException in MissingSummary
Discovered while validating 2.4.0 release (#1639) ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=313480851
1 parent 67a923c commit 35c7777

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

core/src/main/java/com/google/errorprone/bugpatterns/javadoc/MissingSummary.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,10 @@ private Description handle(@Nullable DocTreePath docTreePath, VisitorState state
106106
}
107107
ReturnTree returnTree = findFirst(docTreePath, ReturnTree.class);
108108
if (returnTree != null) {
109-
return generateReturnFix(docTreePath, returnTree, state);
109+
Description description = generateReturnFix(docTreePath, returnTree, state);
110+
if (!description.equals(NO_MATCH)) {
111+
return description;
112+
}
110113
}
111114
SeeTree seeTree = findFirst(docTreePath, SeeTree.class);
112115
if (seeTree != null) {
@@ -127,6 +130,9 @@ private Description generateReturnFix(
127130
DocTreePath docTreePath, ReturnTree returnTree, VisitorState state) {
128131
int pos = ((DCDocComment) docTreePath.getDocComment()).comment.getSourcePos(0);
129132
String description = returnTree.toString().replaceAll("^@return ", "");
133+
if (description.isEmpty()) {
134+
return NO_MATCH;
135+
}
130136
SuggestedFix fix =
131137
SuggestedFix.builder()
132138
.merge(Utils.replace(returnTree, "", state))

core/src/test/java/com/google/errorprone/bugpatterns/javadoc/MissingSummaryTest.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,4 +209,17 @@ public void seeWithHtmlLink() {
209209
"public interface Test {}")
210210
.doTest();
211211
}
212+
213+
@Test
214+
public void emptyReturn() {
215+
helper
216+
.addSourceLines(
217+
"Test.java", //
218+
"interface Test {",
219+
" // BUG: Diagnostic contains:",
220+
" /** @return */",
221+
" int test(int n);",
222+
"}")
223+
.doTest();
224+
}
212225
}

0 commit comments

Comments
 (0)