Repository: checkstyle/checkstyle

Problem statement:
A false negative about the rule ClassMemberImpliedModifier
I have read check documentation: https://checkstyle.sourceforge.io/config_modifier.html#ClassMemberImpliedModifier
I have downloaded the latest checkstyle from: https://checkstyle.org/cmdline.html#Download_and_Run
I have executed the cli and showed it below, as cli describes the problem better than 1,000 words

```bash
/var/tmp $ javac Test.java

/var/tmp $ cat config.xml
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
    "-//Checkstyle//DTD Checkstyle Configuration 1.3//EN"
    "https://checkstyle.org/dtds/configuration_1_3.dtd">
<module name="Checker">
  <property name="severity" value="error"/>
  <property name="fileExtensions" value="java, properties, xml"/>
  <module name="TreeWalker">
    <module name="ClassMemberImpliedModifier" />
  </module>
</module>

/var/tmp $ cat Test.java
public class Test {
  Object obj = new Object() {
    public record BadRecord() {}  // should report a warning in this line
  };
}

/var/tmp $ RUN_LOCALE="-Duser.language=en -Duser.country=US"
/var/tmp $ java $RUN_LOCALE -jar checkstyle-10.1-all.jar -c config.xml Test.java
Starting audit...
Audit done.
```
---
**Describe what you expect in detail.**
---
Hi, I found a false negative about the rule ClassMemberImpliedModifier. CheckStyle should have reported a warning in line 3. But it does not. Thanks for your consideration.
Static modifier is expected to be present.


Hints:
I'm on it.

Patch:
diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/checks/modifier/ClassMemberImpliedModifierCheck.java b/src/main/java/com/puppycrawl/tools/checkstyle/checks/modifier/ClassMemberImpliedModifierCheck.java
--- a/src/main/java/com/puppycrawl/tools/checkstyle/checks/modifier/ClassMemberImpliedModifierCheck.java
+++ b/src/main/java/com/puppycrawl/tools/checkstyle/checks/modifier/ClassMemberImpliedModifierCheck.java
@@ -22,6 +22,7 @@
 import com.puppycrawl.tools.checkstyle.StatelessCheck;
 import com.puppycrawl.tools.checkstyle.api.AbstractCheck;
 import com.puppycrawl.tools.checkstyle.api.DetailAST;
+import com.puppycrawl.tools.checkstyle.api.Scope;
 import com.puppycrawl.tools.checkstyle.api.TokenTypes;
 import com.puppycrawl.tools.checkstyle.utils.ScopeUtil;
 
@@ -237,13 +238,14 @@ public void visitToken(DetailAST ast) {
     }
 
     /**
-     * Checks if ast is in a class, enum, or record block.
+     * Checks if ast is in a class, enum, anon class or record block.
      *
      * @param ast the current ast
-     * @return true if ast is in a class, enum, or record
+     * @return true if ast is in a class, enum, anon class or record
      */
     private static boolean isInTypeBlock(DetailAST ast) {
-        return ScopeUtil.isInClassBlock(ast)
+        return ScopeUtil.isInScope(ast, Scope.ANONINNER)
+                || ScopeUtil.isInClassBlock(ast)
                 || ScopeUtil.isInEnumBlock(ast)
                 || ScopeUtil.isInRecordBlock(ast);
     }


Test patch:
diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/checks/modifier/ClassMemberImpliedModifierCheckTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/checks/modifier/ClassMemberImpliedModifierCheckTest.java
--- a/src/test/java/com/puppycrawl/tools/checkstyle/checks/modifier/ClassMemberImpliedModifierCheckTest.java
+++ b/src/test/java/com/puppycrawl/tools/checkstyle/checks/modifier/ClassMemberImpliedModifierCheckTest.java
@@ -122,6 +122,7 @@ public void testClassMemberImpliedModifierRecords() throws Exception {
             "29:9: " + getCheckMessage(MSG_KEY, "static"),
             "33:9: " + getCheckMessage(MSG_KEY, "static"),
             "37:9: " + getCheckMessage(MSG_KEY, "static"),
+            "43:13: " + getCheckMessage(MSG_KEY, "static"),
         };
         verifyWithInlineConfigParser(
                 getNonCompilablePath("InputClassMemberImpliedModifierRecords.java"),
diff --git a/src/test/resources-noncompilable/com/puppycrawl/tools/checkstyle/checks/modifier/classmemberimpliedmodifier/InputClassMemberImpliedModifierNoViolationRecords.java b/src/test/resources-noncompilable/com/puppycrawl/tools/checkstyle/checks/modifier/classmemberimpliedmodifier/InputClassMemberImpliedModifierNoViolationRecords.java
--- a/src/test/resources-noncompilable/com/puppycrawl/tools/checkstyle/checks/modifier/classmemberimpliedmodifier/InputClassMemberImpliedModifierNoViolationRecords.java
+++ b/src/test/resources-noncompilable/com/puppycrawl/tools/checkstyle/checks/modifier/classmemberimpliedmodifier/InputClassMemberImpliedModifierNoViolationRecords.java
@@ -36,4 +36,11 @@ public static enum InnerEnum1{} // ok
         // Implied modifier 'static' should be explicit. [ClassMemberImpliedModifier]
         public enum InnerEnum2{} // violation
     }
+
+    void method() {
+        Object obj = new Object() {
+            public record BadRecord() {} // ok
+            public static record OkRecord() {} // ok
+        };
+    }
 }
diff --git a/src/test/resources-noncompilable/com/puppycrawl/tools/checkstyle/checks/modifier/classmemberimpliedmodifier/InputClassMemberImpliedModifierRecords.java b/src/test/resources-noncompilable/com/puppycrawl/tools/checkstyle/checks/modifier/classmemberimpliedmodifier/InputClassMemberImpliedModifierRecords.java
--- a/src/test/resources-noncompilable/com/puppycrawl/tools/checkstyle/checks/modifier/classmemberimpliedmodifier/InputClassMemberImpliedModifierRecords.java
+++ b/src/test/resources-noncompilable/com/puppycrawl/tools/checkstyle/checks/modifier/classmemberimpliedmodifier/InputClassMemberImpliedModifierRecords.java
@@ -36,4 +36,12 @@ public static enum InnerEnum1{} // ok
         // Implied modifier 'static' should be explicit. [ClassMemberImpliedModifier]
         public enum InnerEnum2{} // violation
     }
+
+    void method() {
+        Object obj = new Object() {
+            // Implied modifier 'static' should be explicit. [ClassMemberImpliedModifier]
+            public record BadRecord() {} // violation
+            public static record OkRecord() {} // ok
+        };
+    }
 }