Browse Source

Descriptor.toCtClass should never be used on a classinfo, unless it is an array


git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@447 30ef5769-5b8d-40dd-aea6-55b5d6557bb3
tags/rel_3_17_1_ga
jgreene 16 years ago
parent
commit
6b4fd8d02d
1 changed files with 26 additions and 7 deletions
  1. 26
    7
      src/main/javassist/bytecode/analysis/Executor.java

+ 26
- 7
src/main/javassist/bytecode/analysis/Executor.java View File

case 186: case 186:
throw new RuntimeException("Bad opcode 186"); throw new RuntimeException("Bad opcode 186");
case NEW: case NEW:
frame.push(typeFromDesc(constPool.getClassInfo(iter.u16bitAt(pos + 1))));
frame.push(resolveClassInfo(constPool.getClassInfo(iter.u16bitAt(pos + 1))));
break; break;
case NEWARRAY: case NEWARRAY:
evalNewArray(pos, iter, frame); evalNewArray(pos, iter, frame);
Type type = zeroExtend(typeFromDesc(desc)); Type type = zeroExtend(typeFromDesc(desc));


if (opcode == GETFIELD) { if (opcode == GETFIELD) {
Type objectType = typeFromDesc(constPool.getFieldrefClassName(index));
Type objectType = resolveClassInfo(constPool.getFieldrefClassName(index));
verifyAssignable(objectType, simplePop(frame)); verifyAssignable(objectType, simplePop(frame));
} }


while (i > 0) while (i > 0)
verifyAssignable(zeroExtend(types[--i]), simplePop(frame)); verifyAssignable(zeroExtend(types[--i]), simplePop(frame));


String classDesc = constPool.getInterfaceMethodrefClassName(index);
Type objectType = typeFromDesc(classDesc);
String classInfo = constPool.getInterfaceMethodrefClassName(index);
Type objectType = resolveClassInfo(classInfo);
verifyAssignable(objectType, simplePop(frame)); verifyAssignable(objectType, simplePop(frame));


Type returnType = returnTypeFromDesc(desc); Type returnType = returnTypeFromDesc(desc);
verifyAssignable(zeroExtend(types[--i]), simplePop(frame)); verifyAssignable(zeroExtend(types[--i]), simplePop(frame));


if (opcode != INVOKESTATIC) { if (opcode != INVOKESTATIC) {
Type objectType = typeFromDesc(constPool.getMethodrefClassName(index));
Type objectType = resolveClassInfo(constPool.getMethodrefClassName(index));
verifyAssignable(objectType, simplePop(frame)); verifyAssignable(objectType, simplePop(frame));
} }




private void evalNewObjectArray(int pos, CodeIterator iter, Frame frame) throws BadBytecode { private void evalNewObjectArray(int pos, CodeIterator iter, Frame frame) throws BadBytecode {
// Convert to x[] format // Convert to x[] format
Type type = typeFromDesc(constPool.getClassInfo(iter.u16bitAt(pos + 1)));
Type type = resolveClassInfo(constPool.getClassInfo(iter.u16bitAt(pos + 1)));
String name = type.getCtClass().getName(); String name = type.getCtClass().getName();
int opcode = iter.byteAt(pos); int opcode = iter.byteAt(pos);
int dimensions; int dimensions;
verifyAssignable(type, simplePop(frame)); verifyAssignable(type, simplePop(frame));


if (opcode == PUTFIELD) { if (opcode == PUTFIELD) {
Type objectType = typeFromDesc(constPool.getFieldrefClassName(index));
Type objectType = resolveClassInfo(constPool.getFieldrefClassName(index));
verifyAssignable(objectType, simplePop(frame)); verifyAssignable(objectType, simplePop(frame));
} }
} }
frame.setLocal(index + 1, Type.TOP); frame.setLocal(index + 1, Type.TOP);
} }


private Type resolveClassInfo(String info) throws BadBytecode {
CtClass clazz = null;
try {
if (info.charAt(0) == '[') {
clazz = Descriptor.toCtClass(info, classPool);
} else {
clazz = classPool.get(info);
}

} catch (NotFoundException e) {
throw new BadBytecode("Could not find class in descriptor [pos = " + lastPos + "]: " + e.getMessage());
}

if (clazz == null)
throw new BadBytecode("Could not obtain type for descriptor [pos = " + lastPos + "]: " + info);

return Type.get(clazz);
}

private Type typeFromDesc(String desc) throws BadBytecode { private Type typeFromDesc(String desc) throws BadBytecode {
CtClass clazz = null; CtClass clazz = null;
try { try {

Loading…
Cancel
Save