From 22075222e758ee69f9f9cf69291ff83f5924f7fb Mon Sep 17 00:00:00 2001 From: ximsfei <550616352@qq.com> Date: Tue, 8 Oct 2019 22:28:05 +0800 Subject: fixes a bug of ClassFile#renameClass(), some imports could not be successfully renamed --- .../javassist/bytecode/SignatureAttribute.java | 34 +++++++++++----------- 1 file changed, 17 insertions(+), 17 deletions(-) (limited to 'src/main/javassist/bytecode/SignatureAttribute.java') diff --git a/src/main/javassist/bytecode/SignatureAttribute.java b/src/main/javassist/bytecode/SignatureAttribute.java index 1a8a62dc..6a483057 100644 --- a/src/main/javassist/bytecode/SignatureAttribute.java +++ b/src/main/javassist/bytecode/SignatureAttribute.java @@ -121,29 +121,29 @@ public class SignatureAttribute extends AttributeInfo { if (j < 0) break; - StringBuilder nameBuf = new StringBuilder(); - int k = j; - char c; - try { - while ((c = desc.charAt(++k)) != ';') { - nameBuf.append(c); - if (c == '<') { - while ((c = desc.charAt(++k)) != '>') - nameBuf.append(c); - - nameBuf.append(c); - } - } + int k = desc.indexOf(';', j); + if (k < 0) + break; + + int l = desc.indexOf('<', j); + int classEndIndex; + char classEndChar; + if (l < 0 || k < l) { + classEndIndex = k; + classEndChar = ';'; + } else { + classEndIndex = l; + classEndChar = '<'; } - catch (IndexOutOfBoundsException e) { break; } - i = k + 1; - String name = nameBuf.toString(); + i = classEndIndex + 1; + + String name = desc.substring(j + 1, classEndIndex); String name2 = map.get(name); if (name2 != null) { newdesc.append(desc.substring(head, j)); newdesc.append('L'); newdesc.append(name2); - newdesc.append(c); + newdesc.append(classEndChar); head = i; } } -- cgit v1.2.3