Skip to content

Commit 1616f39

Browse files
authored
Merge pull request #1440 from fabriciofx/1428
#1428: Fix error instantiating a rule in a Java 21 project
2 parents 6a963fc + b7044cc commit 1616f39

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

qulice-checkstyle/src/main/java/com/qulice/checkstyle/MultiLineCommentCheck.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public final class MultiLineCommentCheck extends AbstractCheck {
3434
* during the class under test and the field is reinitialized with a new object.
3535
*/
3636
@SuppressWarnings("PMD.AvoidStringBufferField")
37-
private StringBuilder text;
37+
private final StringBuilder text = new StringBuilder();
3838

3939
@Override
4040
public boolean isCommentNodesRequired() {
@@ -63,7 +63,8 @@ public int[] getRequiredTokens() {
6363
@Override
6464
public void visitToken(final DetailAST ast) {
6565
if (ast.getType() == TokenTypes.BLOCK_COMMENT_BEGIN) {
66-
this.text = new StringBuilder(ast.getText());
66+
this.text.setLength(0);
67+
this.text.append(ast.getText());
6768
} else if (ast.getType() == TokenTypes.COMMENT_CONTENT) {
6869
this.text.append(ast.getText());
6970
} else {

qulice-checkstyle/src/main/java/com/qulice/checkstyle/SingleLineCommentCheck.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public final class SingleLineCommentCheck extends AbstractCheck {
3535
* during the class under test and the field is reinitialized with a new object.
3636
*/
3737
@SuppressWarnings("PMD.AvoidStringBufferField")
38-
private StringBuilder line;
38+
private final StringBuilder line = new StringBuilder();
3939

4040
/**
4141
* When inside a block comment, holds begin line number.
@@ -69,7 +69,8 @@ public int[] getRequiredTokens() {
6969
@Override
7070
public void visitToken(final DetailAST ast) {
7171
if (ast.getType() == TokenTypes.BLOCK_COMMENT_BEGIN) {
72-
this.line = new StringBuilder(ast.getText());
72+
this.line.setLength(0);
73+
this.line.append(ast.getText());
7374
this.begin = ast.getLineNo();
7475
} else if (ast.getType() == TokenTypes.COMMENT_CONTENT) {
7576
this.line.append(ast.getText());

0 commit comments

Comments
 (0)