JDK-8334248 : Invalid error for early construction local class constructor method reference
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2024-06-13
  • Updated: 2024-11-27
  • Resolved: 2024-11-15
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 24
24 b25Fixed
Related Reports
Duplicate :  
Duplicate :  
Duplicate :  
Description
The new "flexible constructors" JEP specifies that a local class declared in an early construction context does not have an immediate outer instance, i.e., same behavior as an anonymous class in that situation.

However, the compiler still (incorrectly) tries to verify one in the case of a method reference to the local class' constructor.

Example:

    import java.util.function.Supplier;
    class EarlyLocalCtorRef {
        EarlyLocalCtorRef(int x) {
            class InnerLocal { }
            this(InnerLocal::new);
        }
        EarlyLocalCtorRef(Supplier<Object> s) {
        }
    }

Expected output:

    Successful compilation.

Actual output:

    EarlyLocalCtorRef.java:5: error: cannot reference this before supertype constructor has been called
            this(InnerLocal::new);
                 ^

Comments
Changeset: 5b9932f8 Branch: master Author: Maurizio Cimadamore <mcimadamore@openjdk.org> Date: 2024-11-15 10:07:18 +0000 URL: https://git.openjdk.org/jdk/commit/5b9932f8f3c320f1d2c95403478a6069d05da52a
15-11-2024

A pull request was submitted for review. Branch: master URL: https://git.openjdk.org/jdk/pull/21410 Date: 2024-10-08 14:42:19 +0000
08-10-2024

A pull request was submitted for review. Branch: master URL: https://git.openjdk.org/jdk/pull/19904 Date: 2024-06-26 11:17:50 +0000
09-07-2024

A pull request was submitted for review. URL: https://git.openjdk.org/jdk/pull/19705 Date: 2024-06-13 16:54:04 +0000
13-06-2024