forked from phoedos/pmd
pmd: Fixed bug 1048: CommentContent Rule, String Index out of range Exception
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
???? ??, 2012 - 5.0.2:
|
||||
|
||||
Fixed bug 1044: Unknown option: -excludemarker
|
||||
Fixed bug 1048: CommentContent Rule, String Index out of range Exception
|
||||
|
||||
November 28, 2012 - 5.0.1:
|
||||
|
||||
|
@ -1,3 +1,6 @@
|
||||
/**
|
||||
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
|
||||
*/
|
||||
package net.sourceforge.pmd.lang.java.rule.comments;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -95,7 +98,7 @@ public abstract class AbstractCommentRule extends AbstractJavaRule {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (line.charAt(0) == '*') {
|
||||
if (line.length() > 0 && line.charAt(0) == '*') {
|
||||
filteredLines.add(line.substring(1));
|
||||
continue;
|
||||
}
|
||||
@ -122,7 +125,7 @@ public abstract class AbstractCommentRule extends AbstractJavaRule {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (line.charAt(0) == '*') {
|
||||
if (line.length() > 0 && line.charAt(0) == '*') {
|
||||
filteredLines.add(line.substring(1));
|
||||
continue;
|
||||
}
|
||||
|
@ -0,0 +1,34 @@
|
||||
/**
|
||||
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
|
||||
*/
|
||||
package net.sourceforge.pmd.lang.java.rule.comments;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import net.sourceforge.pmd.lang.java.ast.FormalComment;
|
||||
import net.sourceforge.pmd.lang.java.ast.MultiLineComment;
|
||||
import net.sourceforge.pmd.lang.java.ast.Token;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class AbstractCommentRuleTest {
|
||||
|
||||
private AbstractCommentRule testSubject = new AbstractCommentRule() {};
|
||||
|
||||
/**
|
||||
* Blank lines in comments should not raise an exception.
|
||||
* See bug #1048.
|
||||
*/
|
||||
@Test
|
||||
public void testFilteredCommentIn() {
|
||||
Token token = new Token();
|
||||
token.image = "/* multi line comment with blank lines\n\n\n */";
|
||||
|
||||
String filtered = testSubject.filteredCommentIn(new MultiLineComment(token));
|
||||
assertEquals("multi line comment with blank lines", filtered);
|
||||
|
||||
token.image = "/** a formal comment with blank lines\n\n\n */";
|
||||
filtered = testSubject.filteredCommentIn(new FormalComment(token));
|
||||
assertEquals("a formal comment with blank lines", filtered);
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user