You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The method javassist.bytecode.ClassFile.renameClass(Map) fails when the classes to be renamed are generic. Apparently the problem is due to the fact that Javassist does not modify the constant pool entries that contain generic type signatures.
Let us consider the following program:
public class Main {
public static void main(String[] s) {
final Path pathOfClass = Paths.get("/some/where/A.class");
ClassFile cf = new ClassFile(new DataInputStream(new ByteArrayInputStream(Files.readAllBytes(pathOfClass))));
final HashMap<String, String> renames = new HashMap<>();
renames.put("A", "B");
cf.renameClass(renames);
cf.compact();
cf.write(new DataOutputStream(new FileOutputStream("/some/where/B.class")));
}
}
First case:
$ cat A.java
public class A {
private int x;
private A(int x) { this.x = x; }
public static A make(int x) {
return new A(x);
}
}
$ java Main
$ javap B.class
Compiled from "A.java"
public class B {
public static B make(int);
}
All the occurrences of A are correctly renamed to B.
Second case:
$ cat A.java
public class A<K> {
private K x;
private A(K x) { this.x = x; }
public static <W> A<W> make(W x) {
return new A<W>(x);
}
}
$ java Main
$ javap B.class
Compiled from "A.java"
public class B<K> {
public static <W> A<W> make(W);
}
The static make method incorrectly returns an object of class A.
Tested with Javassist 3.26.0-GA and AdoptOpenJDK version 1.8.0_232.
The text was updated successfully, but these errors were encountered:
The method
javassist.bytecode.ClassFile.renameClass(Map)
fails when the classes to be renamed are generic. Apparently the problem is due to the fact that Javassist does not modify the constant pool entries that contain generic type signatures.Let us consider the following program:
First case:
All the occurrences of
A
are correctly renamed toB
.Second case:
The static
make
method incorrectly returns an object of classA
.Tested with Javassist 3.26.0-GA and AdoptOpenJDK version 1.8.0_232.
The text was updated successfully, but these errors were encountered: