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

Maurizio Cimadamore mcimadamore at openjdk.org
Mon Oct 7 18:54:39 UTC 2024


On Mon, 7 Oct 2024 17:57:37 GMT, Archie Cobbs <acobbs at openjdk.org> wrote:

>> 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.

I guess what I'm asking is whether there's some way to alter the declaration of the problematic methods so that the early-constructor context error is not reported - this seems possible if mergeAbstracts merges info using the interface method as a base symbol?

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

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


More information about the compiler-dev mailing list