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

Vicente Romero vromero at openjdk.java.net
Tue Jan 12 16:42:00 UTC 2021

On Tue, 12 Jan 2021 10:34:34 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:

>> src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Resolve.java line 3327:
>>> 3325:         @Override
>>> 3326:         ReferenceLookupResult unboundResult(ReferenceLookupResult boundRes, ReferenceLookupResult unboundRes) {
>>> 3327:             if (boundRes.isSuccess() && boundRes.sym.isStatic() &&
>> For consistency here I'd prefer to see `boundRes.hasKind(StaticKind.STATIC)` (which is set if the underlying symbol is static). E.g. I think the fix here is really adding the `isSuccess` part, not changing the static check.
> That said - I'm having issue understanding how this has been fixed: if the fix search succeeds and the second search fails to produce a non-static method, then the first search should be preferred. It seems to me that the old code already covers that? Note that `isSuccess` is true whenever the kind != UNDEFINED, so if we check that kind should be STATIC, we already check that is a successful lookup and that the result is static. In other words, I don't see how the new code is different from the old?

I guess that the difference between the new code and the previous one was that in the old code when we check if `boundRes.hasKind(StaticKind.STATIC)` we are checking for a global property of all candidates, meaning that for the previous check to be true, all candidates have to be static. And this is not what the spec is saying, as the spec cares about the staticness, or lack of it, of the most specific method found in each search. Does this make sense?


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

More information about the compiler-dev mailing list