mirror of
https://github.com/corda/corda.git
synced 2024-12-28 16:58:55 +00:00
fix primitive class resolution to avoid mistaking normal classes with names like 'B' for primitive classes
This commit is contained in:
parent
41bee5829e
commit
abd9c2bc8d
@ -1,7 +1,7 @@
|
||||
package java.lang;
|
||||
|
||||
public final class Boolean {
|
||||
public static final Class TYPE = Class.forName("Z");
|
||||
public static final Class TYPE = Class.forCanonicalName("Z");
|
||||
|
||||
private final boolean value;
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
package java.lang;
|
||||
|
||||
public final class Byte extends Number {
|
||||
public static final Class TYPE = Class.forName("B");
|
||||
public static final Class TYPE = Class.forCanonicalName("B");
|
||||
|
||||
private final byte value;
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
package java.lang;
|
||||
|
||||
public final class Character {
|
||||
public static final Class TYPE = Class.forName("C");
|
||||
public static final Class TYPE = Class.forCanonicalName("C");
|
||||
|
||||
private final char value;
|
||||
|
||||
|
@ -26,7 +26,28 @@ public final class Class <T> {
|
||||
return new String(name, 0, name.length - 1, false);
|
||||
}
|
||||
|
||||
public static native Class forName(String name);
|
||||
public static native Class forName(String name)
|
||||
throws ClassNotFoundException;
|
||||
|
||||
private static native Class primitiveClass(char name);
|
||||
|
||||
static Class forCanonicalName(String name) {
|
||||
try {
|
||||
if (name.startsWith("[")) {
|
||||
return forName(name);
|
||||
} else if (name.startsWith("L")) {
|
||||
return forName(name.substring(1, name.length() - 1));
|
||||
} else {
|
||||
if (name.length() == 0) {
|
||||
return primitiveClass(name.charAt(0));
|
||||
} else {
|
||||
throw new ClassNotFoundException(name);
|
||||
}
|
||||
}
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public native boolean isAssignableFrom(Class c);
|
||||
|
||||
|
@ -9,7 +9,7 @@ public class ClassLoader {
|
||||
return instance;
|
||||
}
|
||||
|
||||
public Class loadClass(String name) {
|
||||
public Class loadClass(String name) throws ClassNotFoundException {
|
||||
return Class.forName(name);
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
package java.lang;
|
||||
|
||||
public final class Double {
|
||||
public static final Class TYPE = Class.forName("D");
|
||||
public static final Class TYPE = Class.forCanonicalName("D");
|
||||
|
||||
private final double value;
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
package java.lang;
|
||||
|
||||
public final class Float extends Number {
|
||||
public static final Class TYPE = Class.forName("F");
|
||||
public static final Class TYPE = Class.forCanonicalName("F");
|
||||
|
||||
private final float value;
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
package java.lang;
|
||||
|
||||
public final class Integer extends Number {
|
||||
public static final Class TYPE = Class.forName("I");
|
||||
public static final Class TYPE = Class.forCanonicalName("I");
|
||||
|
||||
private final int value;
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
package java.lang;
|
||||
|
||||
public final class Long extends Number {
|
||||
public static final Class TYPE = Class.forName("J");
|
||||
public static final Class TYPE = Class.forCanonicalName("J");
|
||||
|
||||
private final long value;
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
package java.lang;
|
||||
|
||||
public final class Short extends Number {
|
||||
public static final Class TYPE = Class.forName("S");
|
||||
public static final Class TYPE = Class.forCanonicalName("S");
|
||||
|
||||
private final short value;
|
||||
|
||||
|
@ -4,10 +4,11 @@ import java.util.Map;
|
||||
import java.util.WeakHashMap;
|
||||
|
||||
public class Thread implements Runnable {
|
||||
private long peer;
|
||||
private final Runnable task;
|
||||
private Map<ThreadLocal, Object> locals;
|
||||
private Object sleepLock;
|
||||
private long peer;
|
||||
private boolean interrupted;
|
||||
|
||||
public Thread(Runnable task) {
|
||||
this.task = task;
|
||||
|
@ -1,7 +1,7 @@
|
||||
package java.lang;
|
||||
|
||||
public final class Void {
|
||||
public static final Class TYPE = Class.forName("V");
|
||||
public static final Class TYPE = Class.forCanonicalName("V");
|
||||
|
||||
private Void() { }
|
||||
}
|
||||
|
@ -51,31 +51,35 @@ public class Method<T> extends AccessibleObject implements Member {
|
||||
|
||||
String spec = new String(this.spec, 1, this.spec.length - 1, false);
|
||||
|
||||
for (int i = 0; i < spec.length(); ++i) {
|
||||
char c = spec.charAt(i);
|
||||
if (c == ')') {
|
||||
break;
|
||||
} else if (c == 'L') {
|
||||
int start = i + 1;
|
||||
i = next(';', spec, start);
|
||||
String name = spec.substring(start, i);
|
||||
types[index++] = Class.forName(name);
|
||||
} else if (c == '[') {
|
||||
int start = i;
|
||||
while (spec.charAt(i) == '[') ++i;
|
||||
|
||||
if (spec.charAt(i) == 'L') {
|
||||
i = next(';', spec, i + 1);
|
||||
try {
|
||||
for (int i = 0; i < spec.length(); ++i) {
|
||||
char c = spec.charAt(i);
|
||||
if (c == ')') {
|
||||
break;
|
||||
} else if (c == 'L') {
|
||||
int start = i + 1;
|
||||
i = next(';', spec, start);
|
||||
String name = spec.substring(start, i);
|
||||
types[index++] = Class.forName(name);
|
||||
} else if (c == '[') {
|
||||
int start = i;
|
||||
while (spec.charAt(i) == '[') ++i;
|
||||
|
||||
if (spec.charAt(i) == 'L') {
|
||||
i = next(';', spec, i + 1);
|
||||
String name = spec.substring(start, i);
|
||||
types[index++] = Class.forName(name);
|
||||
} else {
|
||||
String name = spec.substring(start, i + 1);
|
||||
types[index++] = Class.forName(name);
|
||||
}
|
||||
} else {
|
||||
String name = spec.substring(start, i + 1);
|
||||
String name = spec.substring(i, i + 1);
|
||||
types[index++] = Class.forName(name);
|
||||
}
|
||||
} else {
|
||||
String name = spec.substring(i, i + 1);
|
||||
types[index++] = Class.forName(name);
|
||||
}
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
return types;
|
||||
|
@ -87,6 +87,32 @@ Class_forName(Thread* t, jclass, jstring name)
|
||||
}
|
||||
}
|
||||
|
||||
jclass
|
||||
Class_primitiveClass(Thread* t, jclass, jchar name)
|
||||
{
|
||||
switch (name) {
|
||||
case 'B':
|
||||
return pushReference(t, arrayBody(t, t->vm->types, Machine::JbyteType));
|
||||
case 'C':
|
||||
return pushReference(t, arrayBody(t, t->vm->types, Machine::JcharType));
|
||||
case 'D':
|
||||
return pushReference(t, arrayBody(t, t->vm->types, Machine::JdoubleType));
|
||||
case 'F':
|
||||
return pushReference(t, arrayBody(t, t->vm->types, Machine::JfloatType));
|
||||
case 'I':
|
||||
return pushReference(t, arrayBody(t, t->vm->types, Machine::JintType));
|
||||
case 'L':
|
||||
return pushReference(t, arrayBody(t, t->vm->types, Machine::JlongType));
|
||||
case 'S':
|
||||
return pushReference(t, arrayBody(t, t->vm->types, Machine::JshortType));
|
||||
case 'V':
|
||||
return pushReference(t, arrayBody(t, t->vm->types, Machine::JvoidType));
|
||||
default:
|
||||
t->exception = makeIllegalArgumentException(t);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
jboolean
|
||||
Class_isAssignableFrom(Thread* t, jobject this_, jclass that)
|
||||
{
|
||||
|
@ -1375,7 +1375,7 @@ Thread::Thread(Machine* m, object javaThread, Thread* parent):
|
||||
|
||||
populateBuiltinMap(t, m->builtinMap);
|
||||
|
||||
t->javaThread = makeThread(t, 0, 0, 0, reinterpret_cast<int64_t>(t));
|
||||
t->javaThread = makeThread(t, reinterpret_cast<int64_t>(t), 0, 0, 0, 0);
|
||||
} else {
|
||||
threadPeer(this, javaThread) = reinterpret_cast<jlong>(this);
|
||||
parent->child = this;
|
||||
|
@ -125,10 +125,11 @@
|
||||
|
||||
(type thread java/lang/Thread
|
||||
(extends jobject)
|
||||
(int64_t peer)
|
||||
(object task)
|
||||
(object locals)
|
||||
(object sleepLock)
|
||||
(int64_t peer))
|
||||
(uint8_t interrupted))
|
||||
|
||||
(type stackTraceElement java/lang/StackTraceElement
|
||||
(extends jobject)
|
||||
@ -280,29 +281,29 @@
|
||||
(extends jobject)
|
||||
(array uint64_t body))
|
||||
|
||||
(type jbyte B
|
||||
(type jbyte
|
||||
(extends jobject))
|
||||
|
||||
(type jboolean Z
|
||||
(type jboolean
|
||||
(extends jobject))
|
||||
|
||||
(type jshort S
|
||||
(type jshort
|
||||
(extends jobject))
|
||||
|
||||
(type jchar C
|
||||
(type jchar
|
||||
(extends jobject))
|
||||
|
||||
(type jint I
|
||||
(type jint
|
||||
(extends jobject))
|
||||
|
||||
(type jlong L
|
||||
(type jlong
|
||||
(extends jobject))
|
||||
|
||||
(type jfloat F
|
||||
(type jfloat
|
||||
(extends jobject))
|
||||
|
||||
(type jdouble D
|
||||
(type jdouble
|
||||
(extends jobject))
|
||||
|
||||
(type jvoid V
|
||||
(type jvoid
|
||||
(extends jobject))
|
||||
|
Loading…
Reference in New Issue
Block a user