Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a crash in InvalidLink on /// markdown doc comments #4526

Merged
merged 1 commit into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ public static boolean isAtLeast22() {
return FEATURE >= 22;
}

/** Returns true if the current runtime is JDK 23 or newer. */
public static boolean isAtLeast23() {
return FEATURE >= 23;
}

/**
* Returns the latest {@code --release} version.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ static SuggestedFix replace(DocTree docTree, String replacement, VisitorState st
int startPos = getStartPosition(docTree, state);
int endPos =
(int) positions.getEndPosition(compilationUnitTree, getDocCommentTree(state), docTree);
if (endPos == Position.NOPOS) {
if (startPos == Position.NOPOS || endPos == Position.NOPOS) {
return SuggestedFix.emptyFix();
}
return SuggestedFix.replace(startPos, endPos, replacement);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@
package com.google.errorprone.bugpatterns.javadoc;

import static com.google.errorprone.BugCheckerRefactoringTestHelper.TestMode.TEXT_MATCH;
import static org.junit.Assume.assumeTrue;

import com.google.errorprone.BugCheckerRefactoringTestHelper;
import com.google.errorprone.CompilationTestHelper;
import com.google.errorprone.util.RuntimeVersion;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
Expand Down Expand Up @@ -181,4 +183,19 @@ public void emptyLinkTest() {
"}")
.doTest();
}

@Test
public void markdown() {
assumeTrue(RuntimeVersion.isAtLeast23());
helper
.addSourceLines(
"Test.java", //
"public class Test {",
" /// Hello [bar]",
" // BUG: Diagnostic contains: `bar` is a parameter",
" static void foo(int bar) {}",
"}")
.setArgs("--release", "22")
.doTest();
}
}
Loading