[jdk16] RFR: 8231461: static/instance overload leads to 'unexpected static method found in unbound lookup' when resolving method reference [v3]

Vicente Romero vromero at openjdk.java.net
Wed Jan 13 15:43:23 UTC 2021


> This patch fixes the following issue, for code like:
> import java.util.function.*;
>  
> public class Test {
>     public String foo(Object o) { return "foo"; }
>     public static String foo(String o) { return "bar"; }
> 
>     public void test() {
>         Function<String, String> f = Test::foo;
>     }
> }
> javac is issuing an invalid method reference error even though the static method is applicable. This is due to a regression on the implementation of the following assertion on section 15.13.1 of the JLS 14:
> 
> If the first search produces a most specific method that is static , and the set
> of applicable methods produced by the second search contains no non- static
> methods, then the compile-time declaration is the most specified method of
> the first search.
> 
> Apart from fixing the mentioned regression, this patch also adds a debug feature for the compiler to print out the findings during the search for an applicable method reference. The information is printed out if a debug flag is passed to the compiler.
> 
> TIA

Vicente Romero has updated the pull request incrementally with one additional commit since the last revision:

  restoring isSuccess implementation

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

Changes:
  - all: https://git.openjdk.java.net/jdk16/pull/107/files
  - new: https://git.openjdk.java.net/jdk16/pull/107/files/51a5b194..6a09401b

Webrevs:
 - full: https://webrevs.openjdk.java.net/?repo=jdk16&pr=107&range=02
 - incr: https://webrevs.openjdk.java.net/?repo=jdk16&pr=107&range=01-02

  Stats: 1 line in 1 file changed: 0 ins; 0 del; 1 mod
  Patch: https://git.openjdk.java.net/jdk16/pull/107.diff
  Fetch: git fetch https://git.openjdk.java.net/jdk16 pull/107/head:pull/107

PR: https://git.openjdk.java.net/jdk16/pull/107


More information about the compiler-dev mailing list