A DESCRIPTION OF THE PROBLEM :
Javac allows invocation of an inherited instance method from a static method, when the method is inherited twice. The first method argument of the static method is treated as the instance to invoke, which can lead to a Javac crash or VerifyError.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the given example.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Javac shouldn't crash or generate an invalid class.
ACTUAL -
With no arguments:
An exception has occurred in the compiler (23-ea). Please file a bug against the Java compiler via the Java bug reporting page (https://bugreport.java.com) after checking the Bug Database (https://bugs.java.com) for duplicates. Include your program, the following diagnostic, and the parameters passed to the Java compiler in your report. Thank you.
java.lang.NullPointerException: Cannot read field "sym" because "this.lvar[0]" is null
at jdk.compiler/com.sun.tools.javac.jvm.Code.emitop0(Code.java:572)
at jdk.compiler/com.sun.tools.javac.jvm.Items$SelfItem.load(Items.java:369)
at jdk.compiler/com.sun.tools.javac.jvm.Gen.visitIdent(Gen.java:2356)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCIdent.accept(JCTree.java:2704)
at jdk.compiler/com.sun.tools.javac.jvm.Gen.genExpr(Gen.java:859)
at jdk.compiler/com.sun.tools.javac.jvm.Gen.visitApply(Gen.java:1929)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodInvocation.accept(JCTree.java:1857)
at jdk.compiler/com.sun.tools.javac.jvm.Gen.genExpr(Gen.java:859)
at jdk.compiler/com.sun.tools.javac.jvm.Gen.visitReturn(Gen.java:1897)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCReturn.accept(JCTree.java:1769)
at jdk.compiler/com.sun.tools.javac.jvm.Gen.genDef(Gen.java:588)
at jdk.compiler/com.sun.tools.javac.jvm.Gen.genStat(Gen.java:623)
at jdk.compiler/com.sun.tools.javac.jvm.Gen.genStat(Gen.java:609)
at jdk.compiler/com.sun.tools.javac.jvm.Gen.genStats(Gen.java:660)
at jdk.compiler/com.sun.tools.javac.jvm.Gen.internalVisitBlock(Gen.java:1121)
at jdk.compiler/com.sun.tools.javac.jvm.Gen.visitBlock(Gen.java:1085)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:1133)
at jdk.compiler/com.sun.tools.javac.jvm.Gen.genDef(Gen.java:588)
at jdk.compiler/com.sun.tools.javac.jvm.Gen.genStat(Gen.java:623)
at jdk.compiler/com.sun.tools.javac.jvm.Gen.genMethod(Gen.java:949)
at jdk.compiler/com.sun.tools.javac.jvm.Gen.visitMethodDef(Gen.java:912)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:957)
at jdk.compiler/com.sun.tools.javac.jvm.Gen.genDef(Gen.java:588)
at jdk.compiler/com.sun.tools.javac.jvm.Gen.genClass(Gen.java:2494)
at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.genCode(JavaCompiler.java:770)
at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.generate(JavaCompiler.java:1700)
at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.generate(JavaCompiler.java:1668)
at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:977)
at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:319)
at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:178)
at jdk.compiler/com.sun.tools.javac.Main.compile(Main.java:66)
at jdk.compiler/com.sun.tools.javac.Main.main(Main.java:52)
And with an int argument :
Error: Unable to initialize main class bug.C
Caused by: java.lang.VerifyError: Bad local variable type
Exception Details:
Location:
bug/C.test(I)I @0: aload_0
Reason:
Type integer (current frame, locals[0]) is not assignable to reference type
Current Frame:
bci: @0
flags: { }
locals: { integer }
stack: { }
Bytecode:
0000000: 2ab6 000d ac
---------- BEGIN SOURCE ----------
public interface A {
int op();
}
public abstract class B {
abstract int op();
}
public abstract class C extends B implements A {
public static void main(String[] args) {
test(1);
}
public static int test(int x) {
return op();
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Don't attempt to invoke the instance method.
FREQUENCY : always
Javac allows invocation of an inherited instance method from a static method, when the method is inherited twice. The first method argument of the static method is treated as the instance to invoke, which can lead to a Javac crash or VerifyError.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the given example.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Javac shouldn't crash or generate an invalid class.
ACTUAL -
With no arguments:
An exception has occurred in the compiler (23-ea). Please file a bug against the Java compiler via the Java bug reporting page (https://bugreport.java.com) after checking the Bug Database (https://bugs.java.com) for duplicates. Include your program, the following diagnostic, and the parameters passed to the Java compiler in your report. Thank you.
java.lang.NullPointerException: Cannot read field "sym" because "this.lvar[0]" is null
at jdk.compiler/com.sun.tools.javac.jvm.Code.emitop0(Code.java:572)
at jdk.compiler/com.sun.tools.javac.jvm.Items$SelfItem.load(Items.java:369)
at jdk.compiler/com.sun.tools.javac.jvm.Gen.visitIdent(Gen.java:2356)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCIdent.accept(JCTree.java:2704)
at jdk.compiler/com.sun.tools.javac.jvm.Gen.genExpr(Gen.java:859)
at jdk.compiler/com.sun.tools.javac.jvm.Gen.visitApply(Gen.java:1929)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodInvocation.accept(JCTree.java:1857)
at jdk.compiler/com.sun.tools.javac.jvm.Gen.genExpr(Gen.java:859)
at jdk.compiler/com.sun.tools.javac.jvm.Gen.visitReturn(Gen.java:1897)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCReturn.accept(JCTree.java:1769)
at jdk.compiler/com.sun.tools.javac.jvm.Gen.genDef(Gen.java:588)
at jdk.compiler/com.sun.tools.javac.jvm.Gen.genStat(Gen.java:623)
at jdk.compiler/com.sun.tools.javac.jvm.Gen.genStat(Gen.java:609)
at jdk.compiler/com.sun.tools.javac.jvm.Gen.genStats(Gen.java:660)
at jdk.compiler/com.sun.tools.javac.jvm.Gen.internalVisitBlock(Gen.java:1121)
at jdk.compiler/com.sun.tools.javac.jvm.Gen.visitBlock(Gen.java:1085)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:1133)
at jdk.compiler/com.sun.tools.javac.jvm.Gen.genDef(Gen.java:588)
at jdk.compiler/com.sun.tools.javac.jvm.Gen.genStat(Gen.java:623)
at jdk.compiler/com.sun.tools.javac.jvm.Gen.genMethod(Gen.java:949)
at jdk.compiler/com.sun.tools.javac.jvm.Gen.visitMethodDef(Gen.java:912)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:957)
at jdk.compiler/com.sun.tools.javac.jvm.Gen.genDef(Gen.java:588)
at jdk.compiler/com.sun.tools.javac.jvm.Gen.genClass(Gen.java:2494)
at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.genCode(JavaCompiler.java:770)
at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.generate(JavaCompiler.java:1700)
at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.generate(JavaCompiler.java:1668)
at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:977)
at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:319)
at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:178)
at jdk.compiler/com.sun.tools.javac.Main.compile(Main.java:66)
at jdk.compiler/com.sun.tools.javac.Main.main(Main.java:52)
And with an int argument :
Error: Unable to initialize main class bug.C
Caused by: java.lang.VerifyError: Bad local variable type
Exception Details:
Location:
bug/C.test(I)I @0: aload_0
Reason:
Type integer (current frame, locals[0]) is not assignable to reference type
Current Frame:
bci: @0
flags: { }
locals: { integer }
stack: { }
Bytecode:
0000000: 2ab6 000d ac
---------- BEGIN SOURCE ----------
public interface A {
int op();
}
public abstract class B {
abstract int op();
}
public abstract class C extends B implements A {
public static void main(String[] args) {
test(1);
}
public static int test(int x) {
return op();
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Don't attempt to invoke the instance method.
FREQUENCY : always
- links to
-
Commit(master) openjdk/jdk/38c1d651
-
Review(master) openjdk/jdk/20533