JVMS conflicting rules on interface methods
Alex Buckley
alex.buckley at oracle.com
Mon Dec 20 20:30:08 UTC 2021
Yes, thank you. Actioned as https://bugs.openjdk.java.net/browse/JDK-8279039
On 3/12/2021 4:33 AM, x4e_x4e wrote:
> Hello,
>
> JVMS 4.2.2 states:
>
>> Note that a field name or interface method name may be `<init>` or `<clinit>`, but no method invocation instruction may reference `<clinit>` and only the invokespecial instruction (§invokespecial) may reference `<init>`.
>
> (Interface's may have an <init> method). This seems in contradiction with 2.9.1 which states:
>
>> In a class, any non-`void` method named `<init>` is not an instance initialization method. In an interface, any method named `<init>` is not an instance initialization method. Such methods cannot be invoked by any Java Virtual Machine instruction (§4.4.2, §4.9.2) and are rejected by format checking (§4.6, §4.8).
>
> (<init> methods in interfaces are rejected by format checking).
>
> I think it should be clarified whether an <init> method is allowed in an interface classfile.
> Since Java 9 the verifier rejects an <init> method in an interface, so it seems like 2.9.1 is the intended behaviour.
>
> Related links:
> https://bugs.openjdk.java.net/browse/JDK-8122940
> https://bugs.openjdk.java.net/browse/JDK-8135265
>
> Thanks,
> x4e
More information about the jls-jvms-spec-comments
mailing list