Name: skT88420 Date: 10/27/99
C:\javanew>java -version
java version "1.3beta"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3beta-O)
Java(TM) HotSpot Client VM (build 1.3beta-O, mixed mode)
Compile the test program using this command line:
javac -target 1.2 -g ClassNameTest.java
Then run the program like this:
java ClassNameTest
Which should cause the following output:
Exception in thread "main" java.lang.NullPointerException
at ClassNameTest.getMangledClassName(ClassNameTest.java:20)
at ClassNameTest.main(ClassNameTest.java:36)
Now compile like this:
javac -target 1.1 -g ClassNameTest.java
and rerun the program to obtain this output:
ClassNameTest$JunkClassEditor
Using the javap tool you can see that at instruction #8 there is a difference
between the target 1.2 and target 1.1 code. I take this to indicate a code
generation problem, but I suppose it could be a problem with the JVM if the
instruction at #8 is really correct code.
Code from -target 1.2:
Method java.lang.String getMangledClassName(ClassNameTest.JunkInterface)
0 aconst_null
1 aload_1
2 if_acmpne 7
5 aconst_null
6 areturn
7 aload_1
8 invokeinterface (args 1) #2 <InterfaceMethod null>
13 astore_2
14 aload_2
15 invokevirtual #3 <Method java.lang.String getName()>
18 astore_3
19 aload_2
20 invokevirtual #4 <Method java.lang.ClassLoader getClassLoader()>
23 astore 4
25 new #5 <Class java.lang.StringBuffer>
28 dup
29 invokespecial #6 <Method java.lang.StringBuffer()>
32 aload_3
33 invokevirtual #7 <Method java.lang.StringBuffer append(java.lang.String)>
36 ldc #8 <String "Editor">
38 invokevirtual #7 <Method java.lang.StringBuffer append(java.lang.String)>
41 invokevirtual #9 <Method java.lang.String toString()>
44 astore 5
46 aload 5
48 areturn
Code from -target 1.1:
Method java.lang.String getMangledClassName(ClassNameTest.JunkInterface)
0 aconst_null
1 aload_1
2 if_acmpne 7
5 aconst_null
6 areturn
7 aload_1
8 invokevirtual #2 <Method java.lang.Class getClass()>
11 astore_2
12 aload_2
13 invokevirtual #3 <Method java.lang.String getName()>
16 astore_3
17 aload_2
18 invokevirtual #4 <Method java.lang.ClassLoader getClassLoader()>
21 astore 4
23 new #5 <Class java.lang.StringBuffer>
26 dup
27 invokespecial #6 <Method java.lang.StringBuffer()>
30 aload_3
31 invokevirtual #7 <Method java.lang.StringBuffer append(java.lang.String)>
34 ldc #8 <String "Editor">
36 invokevirtual #7 <Method java.lang.StringBuffer append(java.lang.String)>
39 invokevirtual #9 <Method java.lang.String toString()>
42 astore 5
44 aload 5
46 areturn
Here is the program:
//--------Program follows-----------------
public class ClassNameTest
{
public interface JunkInterface
{
public void blahBlahBlah(int j);
}
public static class JunkClass implements JunkInterface
{
public void blahBlahBlah(int j)
{
return;
}
}
public String getMangledClassName(JunkInterface ai)
{
if(null == ai) {
return null;
}
Class itemClass = ai.getClass();
String className = itemClass.getName();
ClassLoader cl = itemClass.getClassLoader();
String editorClassName = className + "Editor";
return editorClassName;
}
public static void main(String args[])
{
JunkInterface o = new JunkClass();
ClassNameTest cnt = new ClassNameTest();
String s = cnt.getMangledClassName(o);
System.out.println(s);
}
}
(Review ID: 97134)
======================================================================
- relates to
-
JDK-4644627 interfaces extend Object?
- Closed
-
JDK-4398789 Correct bytecode for Object method on interface object crashes VM
- Closed