JVMS-001: Interface Flags Combination Violation
Severity: JVM Specification Warning
JVM Spec Reference: Section 4.1, Table 4.1-B
Description
Section titled “Description”According to the Java Virtual Machine Specification, the ACC_INTERFACE flag has strict requirements regarding its relationship with other access flags. Specifically:
If the
ACC_INTERFACEflag is set, theACC_ABSTRACTflag must also be set, and theACC_FINAL,ACC_SUPER,ACC_ENUM, andACC_MODULEflags must not be set.
Examples
Section titled “Examples”Violation: Interface is not marked Abstract
Section titled “Violation: Interface is not marked Abstract”In the JVM, all interfaces are implicitly abstract. Omitting this flag is a spec violation.
; Warning: Interface flag set but ACC_ABSTRACT is missing.class interface public MyInterfaceViolation: Mutually Exclusive Flags
Section titled “Violation: Mutually Exclusive Flags”Interfaces cannot be final (because they must be implemented) or enum (which are specialized classes). Extrait de code
; Warning: Interface cannot be final.class interface final public MyInterface; Warning: Interface cannot be an enum.class interface enum public MyInterfaceSolution
Section titled “Solution”To resolve this warning, ensure that any type flagged as an interface adheres to the following bitmask rules:
Always include ACC_ABSTRACT. Remove ACC_FINAL, ACC_SUPER, ACC_ENUM, and ACC_MODULE.
Standard Interface Definition
Section titled “Standard Interface Definition”A typical public interface should only carry the 0x0601 mask (ACC_PUBLIC | ACC_INTERFACE | ACC_ABSTRACT). Extrait de code
; Correct Flag Usage.class interface abstract public MyInterface