RFR: 8029301: Confusing error message for array creation method reference

Archie L. Cobbs duke at openjdk.org
Mon Feb 20 02:01:11 UTC 2023


The error for an invalid constructor reference of an array type looks like this:

Test.java:3: error: incompatible types: invalid constructor reference
        Runnable r = String[]::new;
                     ^
    constructor Array in class Array cannot be applied to given types
      required: int
      found:    no arguments
      reason: actual and formal argument lists differ in length

The phrase "constructor Array in class Array" is somewhat confusing.

This is a simple patch to reword this type of error to look like this instead:

Test.java:3: error: incompatible types: invalid constructor reference
        Runnable r = String[]::new;
                     ^
    cannot create array from given types
      required: int
      found:    no arguments
      reason:   actual and formal argument lists differ in length

-------------

Commit messages:
 - Improve error referring to "constructor Array in class Array".

Changes: https://git.openjdk.org/jdk/pull/12646/files
 Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=12646&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8029301
  Stats: 31 lines in 4 files changed: 24 ins; 2 del; 5 mod
  Patch: https://git.openjdk.org/jdk/pull/12646.diff
  Fetch: git fetch https://git.openjdk.org/jdk pull/12646/head:pull/12646

PR: https://git.openjdk.org/jdk/pull/12646


More information about the compiler-dev mailing list