Skip to content

Commit

Permalink
fixes a bug of javassist.bytecode.stackmap, which was reported as Issue
Browse files Browse the repository at this point in the history
  • Loading branch information
chibash committed Jul 13, 2020
1 parent 5e3b6a8 commit da043b4
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
Binary file modified javassist.jar
Binary file not shown.
14 changes: 12 additions & 2 deletions src/main/javassist/bytecode/stackmap/TypeData.java
Expand Up @@ -206,7 +206,12 @@ public int getTypeData(ConstPool cp) {
}

@Override
public boolean eq(TypeData d) { return getName().equals(d.getName()); }
public boolean eq(TypeData d) {
if (d.isUninit())
return d.eq(this);
else
return getName().equals(d.getName());
}
}

/* a type variable representing a class type or a basic type.
Expand Down Expand Up @@ -853,7 +858,12 @@ public int getTypeData(ConstPool cp) {
}

@Override
public boolean eq(TypeData d) { return name.equals(d.getName()); }
public boolean eq(TypeData d) {
if (d.isUninit())
return d.eq(this);
else
return name.equals(d.getName());
}

@Override
public void setType(String typeName, ClassPool cp) throws BadBytecode {}
Expand Down
18 changes: 18 additions & 0 deletions src/test/javassist/bytecode/StackMapTest.java
Expand Up @@ -12,6 +12,7 @@
import javassist.ClassPool;
import javassist.CodeConverter;
import javassist.CtClass;
import javassist.CtConstructor;
import javassist.CtMethod;
import javassist.CtNewConstructor;
import javassist.CtNewMethod;
Expand Down Expand Up @@ -830,4 +831,21 @@ MethodInfo getMethodInfo(ClassFile cf, String name, String desc) {

return null;
}

public static class C7 {
public int value;
public static int value2;
public C7() { this(3); }
public C7(int i) {
value = i;
}
}

public void testIssue328() throws Exception {
CtClass cc = loader.get("javassist.bytecode.StackMapTest$C7");
CtConstructor cons = cc.getDeclaredConstructor(new CtClass[] { CtClass.intType });
cons.insertBefore("if ($1 < 0) { super(); if (value2 > 0) { value2++; } return; }");
cc.writeFile();
Object t1 = make(cc.getName());
}
}

0 comments on commit da043b4

Please sign in to comment.