Repository navigation
Description
Parent Issue #19971
I have read check documentation: https://checkstyle.org/checks/sizes/outertypenumber.html
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
vivek@Viveks-MacBook-Air checkstyle % cat > config.xml <<'EOF'
<?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">
<module name="TreeWalker">
<module name="OuterTypeNumber"/>
</module>
</module>
EOF
vivek@Viveks-MacBook-Air checkstyle % cat > InputOuterTypeNumberCompact.java <<'EOF'
void main() { }
class A { }
class B { }
EOF
vivek@Viveks-MacBook-Air checkstyle % RUN_LOCALE="-Duser.language=en -Duser.country=US"
java $RUN_LOCALE -jar target/checkstyle-13.6.0-SNAPSHOT-all.jar -c config.xml InputOuterTypeNumberCompact.java
Starting audit...
[ERROR] InputOuterTypeNumberCompact.java:1:1: Outer types defined is 2 (max allowed is 1). [OuterTypeNumber]
Audit done.
Checkstyle ends with 1 errors.Describe what you expect in detail.
OuterTypeNumberCheck must not flag the compact file. In JEP 512 semantics, class A and class B are nested types of the implicit class that the compiler synthesises for a compact source file. They are members of the implicit class, not outer types. The compact file contains exactly one outer type (the implicit class), so the check should report zero violations.
The check currently counts every CLASS_DEF (and the other type-def tokens) child of the root and increments currentOuterTypeCount once per child. Under the new grammar the root is COMPACT_COMPILATION_UNIT and its CLASS_DEF children are member declarations, but the check treats them the same as COMPILATION_UNIT children.
Expected on the compact input: zero violations.
Same code inside an ordinary class:
vivek@Viveks-MacBook-Air checkstyle % cat > InputOuterTypeNumberOrdinary.java <<'EOF'
public class InputOuterTypeNumberOrdinary {
public void main() { }
class A { }
class B { }
}
EOF
vivek@Viveks-MacBook-Air checkstyle % java $RUN_LOCALE -jar target/checkstyle-13.6.0-SNAPSHOT-all.jar -c config.xml InputOuterTypeNumberOrdinary.java
Starting audit...
Audit done.
Activity
vivek-0509 commentedon Jun 7, 2026
To other contributors: please do not pick this issue for now to avoid duplicate work, as I may already be working on it. There are many other open issues available, so please consider picking those and help us improve the project. Thanks for understanding!
Issue #20268: Fix OuterTypeNumber false positive on JEP 512 compact s…