diff --git a/pom.xml b/pom.xml
index 5f3168388..80dde930c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1092,7 +1092,6 @@
.*.checks.NewlineAtEndOfFileCheck8388
.*.checks.OuterTypeFilenameCheck7192
.*.checks.SuppressWarningsHolder7593
- .*.checks.TrailingCommentCheck9093
.*.checks.TranslationCheck8183
.*.checks.UniquePropertiesCheck\$.*7590
diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/checks/TrailingCommentCheck.java b/src/main/java/com/puppycrawl/tools/checkstyle/checks/TrailingCommentCheck.java
index a2714e568..94269bbcf 100644
--- a/src/main/java/com/puppycrawl/tools/checkstyle/checks/TrailingCommentCheck.java
+++ b/src/main/java/com/puppycrawl/tools/checkstyle/checks/TrailingCommentCheck.java
@@ -155,7 +155,7 @@ public class TrailingCommentCheck extends AbstractFormatCheck {
comment = cppComments.get(lineNo);
lineBefore = line.substring(0, comment.getStartColNo());
}
- else if (cComments.containsKey(lineNo)) {
+ else {
final List commentList = cComments.get(lineNo);
comment = commentList.get(commentList.size() - 1);
lineBefore = line.substring(0, comment.getStartColNo());
@@ -168,8 +168,7 @@ public class TrailingCommentCheck extends AbstractFormatCheck {
}
}
}
- if (comment != null
- && !blankLinePattern.matcher(lineBefore).find()
+ if (!blankLinePattern.matcher(lineBefore).find()
&& !isLegalComment(comment)) {
log(lineNo.intValue(), MSG_KEY);
}
diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/checks/TrailingCommentCheckTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/checks/TrailingCommentCheckTest.java
index d93f365d4..07b54b24a 100644
--- a/src/test/java/com/puppycrawl/tools/checkstyle/checks/TrailingCommentCheckTest.java
+++ b/src/test/java/com/puppycrawl/tools/checkstyle/checks/TrailingCommentCheckTest.java
@@ -21,11 +21,13 @@ package com.puppycrawl.tools.checkstyle.checks;
import static com.puppycrawl.tools.checkstyle.checks.TrailingCommentCheck.MSG_KEY;
+import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import com.puppycrawl.tools.checkstyle.BaseCheckTestSupport;
import com.puppycrawl.tools.checkstyle.DefaultConfiguration;
+import com.puppycrawl.tools.checkstyle.api.DetailAST;
public class TrailingCommentCheckTest extends BaseCheckTestSupport {
private DefaultConfiguration checkConfig;
@@ -60,4 +62,16 @@ public class TrailingCommentCheckTest extends BaseCheckTestSupport {
};
verify(checkConfig, getPath("InputTrailingComment.java"), expected);
}
+
+ @Test
+ public void testCallVisitToken() throws Exception {
+ TrailingCommentCheck check = new TrailingCommentCheck();
+ try {
+ check.visitToken(new DetailAST());
+ Assert.fail();
+ }
+ catch (IllegalStateException ex) {
+ "visitToken() shouldn't be called.".equals(ex.getMessage());
+ }
+ }
}