Name: akC45999 Date: 12/01/97
let we have a class named "bad" that implements an interface "intrf"
but declares interface method m1 as private.
Then, if we try to instantiate it, JVM throws an exception
when executing "new" instruction. The problem is that if we try
to execute the "new" instruction one more time,
different exeption is thrown.
May be worst of all, JVM does not specify any exception
to be thrown in this situation.
----------------- file test.jasm
// the test case is provided by Steve Russell <###@###.###>
// and rewritten in jasm since java compiler would not directly compile such code
abstract interface intrf {
public abstract Method m1:"()V";
} // end Class intrf
class bad implements intrf {
private Method m1:"()V" // <--- should be public
stack 1 locals 1
{
return
}
Method <init>:"()V"
stack 1 locals 1
{
aload_0;
invokespecial java/lang/Object.<init>:"()V";
return;
}
} // end Class bad
public super class test {
public static Method run:"([Ljava/lang/String;Ljava/io/PrintStream;)I"
stack 3 locals 6
{
iconst_0;
istore_2;
iconst_1;
istore_3;
Loop:
new class java/lang/StringBuffer;
dup;
ldc String "step ";
invokespecial Method java/lang/StringBuffer."<init>":"(Ljava/lang/String;)V";
iload_3;
invokevirtual Method java/lang/StringBuffer.append:"(I)Ljava/lang/StringBuffer;";
astore 4;
try t3;
new class bad;
endtry t3;
pop;
iconst_2;
istore_2;
aload 4;
ldc String " no exception";
invokevirtual Method java/lang/StringBuffer.append:"(Ljava/lang/String;)Ljava/lang/StringBuffer;";
pop;
goto Print;
catch t3 java/lang/Throwable;
astore 5;
aload 4;
ldc String " exception: ";
invokevirtual Method java/lang/StringBuffer.append:"(Ljava/lang/String;)Ljava/lang/StringBuffer;";
aload 5;
invokevirtual Method java/lang/StringBuffer.append:"(Ljava/lang/Object;)Ljava/lang/StringBuffer;";
pop;
Print:
aload_1;
aload 4;
invokevirtual Method java/io/PrintStream.println:"(Ljava/lang/Object;)V";
Continue:
iinc 3, 1;
iload_3;
iconst_2;
if_icmple Loop;
iload_2;
ireturn;
}
public static Method main:"([Ljava/lang/String;)V"
stack 2 locals 1
{
aload_0;
getstatic Field java/lang/System.out:"Ljava/io/PrintStream;";
invokestatic Method run:"([Ljava/lang/String;Ljava/io/PrintStream;)I";
bipush 95;
iadd;
invokestatic Method java/lang/System.exit:"(I)V";
return;
}
} // end Class test
----------------- end of file test.jasm
Running the test:
novo64% jasm test.jasm
novo64% java test
step 1 exception: java.lang.IllegalAccessError: Unimplemented interface method
step 2 exception: java.lang.IncompatibleClassChangeError: bad
novo64%
======================================================================