From: Pietro Braione Date: Tue, 21 Jan 2020 17:32:06 +0000 (+0100) Subject: Fix renaming of classes in presence of generic signatures and nested X-Git-Tag: rel_3_29_0_ga~11^2~2 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=87826031561c75238bdf99e812829f195b831d5c;p=javassist.git Fix renaming of classes in presence of generic signatures and nested classes. --- diff --git a/src/main/javassist/bytecode/SignatureAttribute.java b/src/main/javassist/bytecode/SignatureAttribute.java index 1a8a62dc..d6515fe0 100644 --- a/src/main/javassist/bytecode/SignatureAttribute.java +++ b/src/main/javassist/bytecode/SignatureAttribute.java @@ -117,34 +117,56 @@ public class SignatureAttribute extends AttributeInfo { int head = 0; int i = 0; for (;;) { - int j = desc.indexOf('L', i); + final int j = desc.indexOf('L', i); if (j < 0) break; StringBuilder nameBuf = new StringBuilder(); + StringBuilder genericParamBuf = new StringBuilder(); + final ArrayList nameBufs = new ArrayList<>(); + final ArrayList genericParamBufs = new ArrayList<>(); int k = j; char c; try { while ((c = desc.charAt(++k)) != ';') { - nameBuf.append(c); if (c == '<') { + genericParamBuf.append(c); while ((c = desc.charAt(++k)) != '>') - nameBuf.append(c); - - nameBuf.append(c); + genericParamBuf.append(c); + + genericParamBuf.append(c); + } else if (c == '.') { + nameBufs.add(nameBuf); + genericParamBufs.add(genericParamBuf); + nameBuf = new StringBuilder(); + genericParamBuf = new StringBuilder(); + } else { + nameBuf.append(c); } } } catch (IndexOutOfBoundsException e) { break; } + nameBufs.add(nameBuf); + genericParamBufs.add(genericParamBuf); i = k + 1; - String name = nameBuf.toString(); + + String name = String.join("$", nameBufs.toArray(new StringBuilder[0])); String name2 = map.get(name); if (name2 != null) { - newdesc.append(desc.substring(head, j)); - newdesc.append('L'); - newdesc.append(name2); - newdesc.append(c); - head = i; + final String[] name2Split = name2.split("\\$"); + if (nameBufs.size() == name2Split.length) { + newdesc.append(desc.substring(head, j)); + newdesc.append('L'); + for (int z = 0; z < name2Split.length; ++z) { + if (z > 0) { + newdesc.append('.'); + } + newdesc.append(name2Split[z]); + newdesc.append(genericParamBufs.get(z).toString()); + } + newdesc.append(c); //the final semicolon + head = i; + } } }