mirror of
https://github.com/corda/corda.git
synced 2025-01-03 19:54:13 +00:00
8ee7e8124a
When we initialize the vtables for bootstrap Java classes such as java.lang.NullPointerException (i.e. classes which the VM has built-in knowledge of), we assign the superclass's vtable to any class which has no declared virtual methods of its own. However, that vtable will be null if we haven't initialized the superclass yet. Therefore, we must order this process such that no class is initialized until after all its superclasses.
133 lines
2.7 KiB
Java
133 lines
2.7 KiB
Java
public class NullPointer {
|
|
private int x;
|
|
private Object y;
|
|
|
|
private static void throw_(Object o) {
|
|
o.toString();
|
|
}
|
|
|
|
private static void throwAndCatch(Object o) {
|
|
try {
|
|
o.toString();
|
|
throw new RuntimeException();
|
|
} catch (NullPointerException e) {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
|
|
public static void main(String[] args) {
|
|
try {
|
|
((Object) null).getClass();
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
}
|
|
|
|
try {
|
|
throw_(null);
|
|
throw new RuntimeException();
|
|
} catch (NullPointerException e) {
|
|
e.printStackTrace();
|
|
}
|
|
|
|
throwAndCatch(null);
|
|
|
|
// invokeinterface
|
|
try {
|
|
((Runnable) null).run();
|
|
throw new RuntimeException();
|
|
} catch (NullPointerException e) {
|
|
e.printStackTrace();
|
|
}
|
|
|
|
// invokevirtual
|
|
try {
|
|
((Object) null).toString();
|
|
throw new RuntimeException();
|
|
} catch (NullPointerException e) {
|
|
e.printStackTrace();
|
|
}
|
|
|
|
// arraylength
|
|
try {
|
|
int a = ((byte[]) null).length;
|
|
throw new RuntimeException();
|
|
} catch (NullPointerException e) {
|
|
e.printStackTrace();
|
|
}
|
|
|
|
// iaload
|
|
try {
|
|
int a = ((byte[]) null)[42];
|
|
throw new RuntimeException();
|
|
} catch (NullPointerException e) {
|
|
e.printStackTrace();
|
|
}
|
|
|
|
// aaload
|
|
try {
|
|
Object a = ((Object[]) null)[42];
|
|
throw new RuntimeException();
|
|
} catch (NullPointerException e) {
|
|
e.printStackTrace();
|
|
}
|
|
|
|
// getfield (int)
|
|
try {
|
|
int a = ((NullPointer) null).x;
|
|
throw new RuntimeException();
|
|
} catch (NullPointerException e) {
|
|
e.printStackTrace();
|
|
}
|
|
|
|
// getfield (Object)
|
|
try {
|
|
Object a = ((NullPointer) null).y;
|
|
throw new RuntimeException();
|
|
} catch (NullPointerException e) {
|
|
e.printStackTrace();
|
|
}
|
|
|
|
// iastore
|
|
try {
|
|
((byte[]) null)[42] = 42;
|
|
throw new RuntimeException();
|
|
} catch (NullPointerException e) {
|
|
e.printStackTrace();
|
|
}
|
|
|
|
// aastore
|
|
try {
|
|
((Object[]) null)[42] = null;
|
|
throw new RuntimeException();
|
|
} catch (NullPointerException e) {
|
|
e.printStackTrace();
|
|
}
|
|
|
|
// putfield (int)
|
|
try {
|
|
((NullPointer) null).x = 42;
|
|
throw new RuntimeException();
|
|
} catch (NullPointerException e) {
|
|
e.printStackTrace();
|
|
}
|
|
|
|
// putfield (Object)
|
|
try {
|
|
((NullPointer) null).y = null;
|
|
throw new RuntimeException();
|
|
} catch (NullPointerException e) {
|
|
e.printStackTrace();
|
|
}
|
|
|
|
// monitorenter
|
|
try {
|
|
synchronized ((Object) null) {
|
|
int a = 42;
|
|
}
|
|
throw new RuntimeException();
|
|
} catch (NullPointerException e) {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
}
|