pmd/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/CommentUtil.java
Affects PMD Version: latest version
Description: I'm working to develop my own comment rule to find all code in comment , then I use CommentUtils. I tried to multiline the comment ,but found StringIndexOutOfBoundsException when testing by a test project. actually, it happens in line 108,when it goes to charAt(0)
if (line.charAt(0) == '*') {
filteredLines.add(line.substring(1));
continue;
}
because sometime we make a comment like this
/*
sometime we use ctrl+shift+/ to make a multiLineComment(not use by /** )
<--- here, thie line causes a string ""
*/
In line 3,when using CommentUtil.multiLinesIn(),this variable string line = "",cause there is nothing!
so "".charAt(0) throws StringIndexOutOfBoundsException.
In my code,I add a StringUtil.isEmpty(line) to check it. In my comment rule, every empty string is also useful, because I use it to count beginLineNumber. I don't whether PMD provides a better way to multiLine the multiComment or JavaDocComment? I only find this CommentUtil useful, so I hope you guys to add a empty check beyond line 96 just like following code:
String line = rawLine.trim();
if(StringUtil.isEmpty(line)){
continue;
}
if (line.startsWith("//")) {
filteredLines.add(line.substring(2));
continue;
}
...
or we can use if("".equals(line)) to check it.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4