diff --git a/p3c-pmd/src/main/java/com/alibaba/p3c/pmd/lang/java/rule/comment/RemoveCommentedCodeRule.java b/p3c-pmd/src/main/java/com/alibaba/p3c/pmd/lang/java/rule/comment/RemoveCommentedCodeRule.java index ed398554995c6eaee0fca2b21c52d10eb3a6174b..a880be6f5b1316e40d458c6e6f7987417a1e96e6 100644 --- a/p3c-pmd/src/main/java/com/alibaba/p3c/pmd/lang/java/rule/comment/RemoveCommentedCodeRule.java +++ b/p3c-pmd/src/main/java/com/alibaba/p3c/pmd/lang/java/rule/comment/RemoveCommentedCodeRule.java @@ -44,6 +44,8 @@ public class RemoveCommentedCodeRule extends AbstractAliCommentRule { private static final Pattern SUPPRESS_PATTERN = Pattern.compile("\\s*///.*", Pattern.DOTALL); + private static final Pattern PRE_TAG_PATTERN = Pattern.compile(".*
.*", Pattern.DOTALL);
+
     private static final Pattern IMPORT_PATTERN = Pattern.compile(".*import\\s(static\\s)?(\\w*\\.)*\\w*;.*",
         Pattern.DOTALL);
 
@@ -125,6 +127,11 @@ public class RemoveCommentedCodeRule extends AbstractAliCommentRule {
     protected CommentPatternEnum scanCommentedCode(String content) {
         CommentPatternEnum pattern = CommentPatternEnum.NONE;
 
+        // Skip comment which contains pre tag.
+        if (PRE_TAG_PATTERN.matcher(content).matches()) {
+            return pattern;
+        }
+
         if (IMPORT_PATTERN.matcher(content).matches()) {
             pattern = CommentPatternEnum.IMPORT;
         } else if (FIELD_PATTERN.matcher(content).matches()) {
diff --git a/p3c-pmd/src/test/resources/com/alibaba/p3c/pmd/lang/java/rule/comment/xml/RemoveCommentedCodeRule.xml b/p3c-pmd/src/test/resources/com/alibaba/p3c/pmd/lang/java/rule/comment/xml/RemoveCommentedCodeRule.xml
index 8e3669f4b457bf39734b35bc34adbc98f2275623..a8293e129b012cc2ce3181ed108eda1e61d64fee 100644
--- a/p3c-pmd/src/test/resources/com/alibaba/p3c/pmd/lang/java/rule/comment/xml/RemoveCommentedCodeRule.xml
+++ b/p3c-pmd/src/test/resources/com/alibaba/p3c/pmd/lang/java/rule/comment/xml/RemoveCommentedCodeRule.xml
@@ -103,4 +103,37 @@ public class Test {
         
     
 
+    
+    
+
+    
+        Code without pre tag
+        1
+        1
+        
+    
+
+    
+ * import net.sourceforge.pmd.lang.java.ast.ASTCompilationUnit;
+ * 
+ */ +public class Test { +} + ]]> + + + + Code in pre tag + 0 + + + \ No newline at end of file