JDK-8357535 : javac incorrectly accepts local class instantiation in static context
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 16,25
  • Priority: P4
  • Status: Closed
  • Resolution: Not an Issue
  • OS: generic
  • CPU: generic
  • Submitted: 2025-05-22
  • Updated: 2025-05-22
  • Resolved: 2025-05-22
Related Reports
Causes :  
Description
ADDITIONAL SYSTEM INFORMATION :
wsl2-ubuntu 22.04
Linux 5.15.167.4-microsoft-standard-WSL2 #1 SMP Tue Nov 5 00:21:55 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux

Java Version:
java 21.0.7 2025-04-15 LTS
Java(TM) SE Runtime Environment (build 21.0.7+8-LTS-245)
Java HotSpot(TM) 64-Bit Server VM (build 21.0.7+8-LTS-245, mixed mode, sharing)

Javac Version:
javac 21.0.7


A DESCRIPTION OF THE PROBLEM :
The following test program can be compiled by javac, however, the code is invalid as the local class is used in a static context.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
javac Test.java

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The source code should be rejected as invalid.
ACTUAL -
The source code compiles successfully.

---------- BEGIN SOURCE ----------
public class Test {
    public static void main(String[] args) {
        class Nest {
            public static void main(String[] args) {
                Nest outer = new Nest();
            }
        }
    }
}
---------- END SOURCE ----------


Comments
Impact -> M (Somewhere in-between the extremes) Likelihood -> L (Not an issue) Workaround -> M (Somewhere in-between the extremes) Priority -> P4
22-05-2025

The observations on Windows 11: JDK 16ea+25: javac rejected the code. JDK 16ea+26: javac compiles successfully It looks like JDK-8254105 allows static members to be declared in inner classes. Closed as not an issue.
22-05-2025