GeezerVison is showing github.com — [Java] Crash when encountering a java comment at the end of a file · Issue #6014 · pmd/pmd
[Java] Crash when encountering a java comment at the end of a file #6014
Description
Affects PMD Version: 7.16.0
Description:
PMD crashes when it encounters a comment // at the very end of a file (no line breaks).
Exception Stacktrace:
java.lang.StringIndexOutOfBoundsException: String index out of range: 2
at net.sourceforge.pmd.lang.document.Chars.charAt(Chars.java:450)
at net.sourceforge.pmd.lang.java.ast.internal.JavaAstUtils.isMarkdownComment(JavaAstUtils.java:801)
at net.sourceforge.pmd.lang.java.ast.ASTCompilationUnit.setComments(ASTCompilationUnit.java:76)
at net.sourceforge.pmd.lang.java.ast.JavaParserImpl.CompilationUnit(JavaParserImpl.java:467)
at net.sourceforge.pmd.lang.java.ast.JavaParser.parseImpl(JavaParser.java:57)
at net.sourceforge.pmd.lang.java.ast.JavaParser.parseImpl(JavaParser.java:25)
at net.sourceforge.pmd.lang.ast.impl.javacc.JjtreeParserAdapter.parse(JjtreeParserAdapter.java:36)
at net.sourceforge.pmd.lang.impl.PmdRunnable.parse(PmdRunnable.java:112)
at net.sourceforge.pmd.lang.impl.PmdRunnable.processSource(PmdRunnable.java:132)
at net.sourceforge.pmd.lang.impl.PmdRunnable.run(PmdRunnable.java:80)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:572)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:317)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)
at java.base/java.lang.Thread.run(Thread.java:1583)
Code Sample demonstrating the issue:
Make sure that there are no chars not even line-breaks after the comment!
NOTE: May require some java code above to actually be detected as a java class.
Steps to reproduce:
- Create a Java file with a
// at the end as described above
- PMD crashes
Running PMD through: IntelliJ plugin
Activity
UncleOwen commented on Aug 27, 2025
That must be the shortest, complete bug repro I've ever seen.
Reacted by Alex "Blex" B, Piotrek Żygieło, Juan Martín Sotuyo Dodero and Clément Fournier
added a commit that references this issue
on Sep 1, 2025This issue will close once commit e457ddd is merged into the 'main' branch.e457ddd
Metadata
Metadata
Development
No branches or pull requestsIssue actions