JVMS conflicting rules on interface methods
x4e_x4e
x4e_x4e at protonmail.com
Fri Mar 12 12:33:23 UTC 2021
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