fix primitive class resolution to avoid mistaking normal classes with names like 'B' for primitive classes

This commit is contained in:
Joel Dice 2007-07-28 10:55:24 -06:00
parent 41bee5829e
commit abd9c2bc8d
16 changed files with 95 additions and 42 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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);

View File

@ -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);
}
}

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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() { }
}

View File

@ -51,6 +51,7 @@ public class Method<T> extends AccessibleObject implements Member {
String spec = new String(this.spec, 1, this.spec.length - 1, false);
try {
for (int i = 0; i < spec.length(); ++i) {
char c = spec.charAt(i);
if (c == ')') {
@ -77,6 +78,9 @@ public class Method<T> extends AccessibleObject implements Member {
types[index++] = Class.forName(name);
}
}
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
return types;
}

View File

@ -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)
{

View File

@ -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;

View File

@ -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))