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

Flexible Constructor Bodies generates a compilation error when compiling a user supplied java.lang.Object class

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 26
    • 22
    • tools
    • None
    • master

      The "Flexible Constructor Bodies" implementation generates an (incorrect) error for a rare case where a user supplied java.lang.Object class is compiled.

      Consider the attached Object.java file. When compiling with `-source 8`, till Java 21, this compiles fine:

      $JDK21_HOME/bin/javac -source 8 /tmp/Object.java
      warning: [options] bootstrap class path not set in conjunction with -source 8
      warning: [options] source value 8 is obsolete and will be removed in a future release
      warning: [options] To suppress warnings about obsolete options, use -Xlint:-options.
      3 warnings

      echo $?
      0

      However, starting Java 22 (including Java 25 and current mainline) it generates the following (incorrect) error:

      $JAVA25_HOME/bin/javac -source 8 /tmp/Object.java
      ...
      /tmp/Object.java:9: error: flexible constructors is not supported in -source 8
              x = 0;
              ^
        (use -source 25 or higher to enable flexible constructors)
      1 error
      3 warnings

      echo $?
      1

            mcimadamore Maurizio Cimadamore
            jpai Jaikiran Pai
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: