RFR: 8337980: Javac allows invocation of an inherited instance method from a static method [v2]

Archie Cobbs acobbs at openjdk.org
Mon Oct 7 18:00:38 UTC 2024


On Mon, 7 Oct 2024 15:51:08 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:

>> Archie Cobbs has updated the pull request with a new target base due to a merge or a rebase. The incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains two additional commits since the last revision:
>> 
>>  - Merge branch 'master' into JDK-8337980
>>  - Avoid crash caused by failure to resolve a valid AmbiguityError.
>
> test/langtools/tools/javac/resolve/MethodAmbiguityCrash2.java line 23:
> 
>> 21: 
>> 22:         public C() {
>> 23:             this(op());     // compile should fail here
> 
> Question: the `mergeAbstracts` method IIRC returns a new method symbol whose owner and flags are those of the most specific signature. So, I wonder, if `B::op` returned `Object` and `A::op` returned `String`, would we still see the problem?

By the time `mergeAbstracts` is called in the patched version of the code, the problem in the original version of the code has already occurred, i.e., the behavior of `mergeAbstracts` is not involved in how the bug happens. I verified that with those changes (`B::op` returning `Object` and `A::op` returning `String`) the verify error still occurs - even when you change the other constructor to `public C(String x)` (so that `B::op` would have an incompatible return value). I also verified that the modified example also works correctly with the PR applied.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/20533#discussion_r1790654078


More information about the compiler-dev mailing list