Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8357535

javac incorrectly accepts local class instantiation in static context

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P4 P4
    • None
    • 16, 25
    • tools
    • generic
    • generic

      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 ----------

            tongwan Andrew Wang
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: