mirror of
https://github.com/corda/corda.git
synced 2024-12-29 09:18:58 +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;
|
package java.lang;
|
||||||
|
|
||||||
public final class Boolean {
|
public final class Boolean {
|
||||||
public static final Class TYPE = Class.forName("Z");
|
public static final Class TYPE = Class.forCanonicalName("Z");
|
||||||
|
|
||||||
private final boolean value;
|
private final boolean value;
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package java.lang;
|
package java.lang;
|
||||||
|
|
||||||
public final class Byte extends Number {
|
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;
|
private final byte value;
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package java.lang;
|
package java.lang;
|
||||||
|
|
||||||
public final class Character {
|
public final class Character {
|
||||||
public static final Class TYPE = Class.forName("C");
|
public static final Class TYPE = Class.forCanonicalName("C");
|
||||||
|
|
||||||
private final char value;
|
private final char value;
|
||||||
|
|
||||||
|
@ -26,7 +26,28 @@ public final class Class <T> {
|
|||||||
return new String(name, 0, name.length - 1, false);
|
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);
|
public native boolean isAssignableFrom(Class c);
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@ public class ClassLoader {
|
|||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Class loadClass(String name) {
|
public Class loadClass(String name) throws ClassNotFoundException {
|
||||||
return Class.forName(name);
|
return Class.forName(name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package java.lang;
|
package java.lang;
|
||||||
|
|
||||||
public final class Double {
|
public final class Double {
|
||||||
public static final Class TYPE = Class.forName("D");
|
public static final Class TYPE = Class.forCanonicalName("D");
|
||||||
|
|
||||||
private final double value;
|
private final double value;
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package java.lang;
|
package java.lang;
|
||||||
|
|
||||||
public final class Float extends Number {
|
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;
|
private final float value;
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package java.lang;
|
package java.lang;
|
||||||
|
|
||||||
public final class Integer extends Number {
|
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;
|
private final int value;
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package java.lang;
|
package java.lang;
|
||||||
|
|
||||||
public final class Long extends Number {
|
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;
|
private final long value;
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package java.lang;
|
package java.lang;
|
||||||
|
|
||||||
public final class Short extends Number {
|
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;
|
private final short value;
|
||||||
|
|
||||||
|
@ -4,10 +4,11 @@ import java.util.Map;
|
|||||||
import java.util.WeakHashMap;
|
import java.util.WeakHashMap;
|
||||||
|
|
||||||
public class Thread implements Runnable {
|
public class Thread implements Runnable {
|
||||||
|
private long peer;
|
||||||
private final Runnable task;
|
private final Runnable task;
|
||||||
private Map<ThreadLocal, Object> locals;
|
private Map<ThreadLocal, Object> locals;
|
||||||
private Object sleepLock;
|
private Object sleepLock;
|
||||||
private long peer;
|
private boolean interrupted;
|
||||||
|
|
||||||
public Thread(Runnable task) {
|
public Thread(Runnable task) {
|
||||||
this.task = task;
|
this.task = task;
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package java.lang;
|
package java.lang;
|
||||||
|
|
||||||
public final class Void {
|
public final class Void {
|
||||||
public static final Class TYPE = Class.forName("V");
|
public static final Class TYPE = Class.forCanonicalName("V");
|
||||||
|
|
||||||
private Void() { }
|
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);
|
String spec = new String(this.spec, 1, this.spec.length - 1, false);
|
||||||
|
|
||||||
for (int i = 0; i < spec.length(); ++i) {
|
try {
|
||||||
char c = spec.charAt(i);
|
for (int i = 0; i < spec.length(); ++i) {
|
||||||
if (c == ')') {
|
char c = spec.charAt(i);
|
||||||
break;
|
if (c == ')') {
|
||||||
} else if (c == 'L') {
|
break;
|
||||||
int start = i + 1;
|
} else if (c == 'L') {
|
||||||
i = next(';', spec, start);
|
int start = i + 1;
|
||||||
String name = spec.substring(start, i);
|
i = next(';', spec, start);
|
||||||
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);
|
String name = spec.substring(start, i);
|
||||||
types[index++] = Class.forName(name);
|
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 {
|
} else {
|
||||||
String name = spec.substring(start, i + 1);
|
String name = spec.substring(i, i + 1);
|
||||||
types[index++] = Class.forName(name);
|
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;
|
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
|
jboolean
|
||||||
Class_isAssignableFrom(Thread* t, jobject this_, jclass that)
|
Class_isAssignableFrom(Thread* t, jobject this_, jclass that)
|
||||||
{
|
{
|
||||||
|
@ -1375,7 +1375,7 @@ Thread::Thread(Machine* m, object javaThread, Thread* parent):
|
|||||||
|
|
||||||
populateBuiltinMap(t, m->builtinMap);
|
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 {
|
} else {
|
||||||
threadPeer(this, javaThread) = reinterpret_cast<jlong>(this);
|
threadPeer(this, javaThread) = reinterpret_cast<jlong>(this);
|
||||||
parent->child = this;
|
parent->child = this;
|
||||||
|
@ -125,10 +125,11 @@
|
|||||||
|
|
||||||
(type thread java/lang/Thread
|
(type thread java/lang/Thread
|
||||||
(extends jobject)
|
(extends jobject)
|
||||||
|
(int64_t peer)
|
||||||
(object task)
|
(object task)
|
||||||
(object locals)
|
(object locals)
|
||||||
(object sleepLock)
|
(object sleepLock)
|
||||||
(int64_t peer))
|
(uint8_t interrupted))
|
||||||
|
|
||||||
(type stackTraceElement java/lang/StackTraceElement
|
(type stackTraceElement java/lang/StackTraceElement
|
||||||
(extends jobject)
|
(extends jobject)
|
||||||
@ -280,29 +281,29 @@
|
|||||||
(extends jobject)
|
(extends jobject)
|
||||||
(array uint64_t body))
|
(array uint64_t body))
|
||||||
|
|
||||||
(type jbyte B
|
(type jbyte
|
||||||
(extends jobject))
|
(extends jobject))
|
||||||
|
|
||||||
(type jboolean Z
|
(type jboolean
|
||||||
(extends jobject))
|
(extends jobject))
|
||||||
|
|
||||||
(type jshort S
|
(type jshort
|
||||||
(extends jobject))
|
(extends jobject))
|
||||||
|
|
||||||
(type jchar C
|
(type jchar
|
||||||
(extends jobject))
|
(extends jobject))
|
||||||
|
|
||||||
(type jint I
|
(type jint
|
||||||
(extends jobject))
|
(extends jobject))
|
||||||
|
|
||||||
(type jlong L
|
(type jlong
|
||||||
(extends jobject))
|
(extends jobject))
|
||||||
|
|
||||||
(type jfloat F
|
(type jfloat
|
||||||
(extends jobject))
|
(extends jobject))
|
||||||
|
|
||||||
(type jdouble D
|
(type jdouble
|
||||||
(extends jobject))
|
(extends jobject))
|
||||||
|
|
||||||
(type jvoid V
|
(type jvoid
|
||||||
(extends jobject))
|
(extends jobject))
|
||||||
|
Loading…
Reference in New Issue
Block a user