Author: britter Date: Sat Jul 2 16:51:15 2016 New Revision: 1751083 URL: http://svn.apache.org/viewvc?rev=1751083&view=rev Log: BCEL-262: InvokeInstruction.getClassName(ConstantPoolGen) should throw an exception when it detects an array. Thanks to Mark Roberts.
Modified: commons/proper/bcel/trunk/RELEASE-NOTES.txt commons/proper/bcel/trunk/src/changes/changes.xml commons/proper/bcel/trunk/src/main/java/org/apache/bcel/generic/InvokeInstruction.java Modified: commons/proper/bcel/trunk/RELEASE-NOTES.txt URL: http://svn.apache.org/viewvc/commons/proper/bcel/trunk/RELEASE-NOTES.txt?rev=1751083&r1=1751082&r2=1751083&view=diff ============================================================================== --- commons/proper/bcel/trunk/RELEASE-NOTES.txt [utf-8] (original) +++ commons/proper/bcel/trunk/RELEASE-NOTES.txt [utf-8] Sat Jul 2 16:51:15 2016 @@ -190,6 +190,8 @@ o BCEL-177: When reading the number of p CHANGES: ======== +o BCEL-262: InvokeInstruction.getClassName(ConstantPoolGen) should throw an + exception when it detects an array. Thanks to Mark Roberts. o BCEL-230: Document the Java platform requirement clearly and early. o BCEL-211: Some additional clone methods should be public. o BCEL-127: Document that Instruction Factory returns singleton instances. Modified: commons/proper/bcel/trunk/src/changes/changes.xml URL: http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/changes/changes.xml?rev=1751083&r1=1751082&r2=1751083&view=diff ============================================================================== --- commons/proper/bcel/trunk/src/changes/changes.xml [utf-8] (original) +++ commons/proper/bcel/trunk/src/changes/changes.xml [utf-8] Sat Jul 2 16:51:15 2016 @@ -107,6 +107,8 @@ Source compatible - Yes, sort of; For full information about API changes please see the extended Clirr report: http://commons.apache.org/bcel/clirr-report.html"> + <action issue="BCEL-262" type="update" dev="britter" due-to="Mark Roberts">InvokeInstruction.getClassName(ConstantPoolGen) + should throw an exception when it detects an array.</action> <action issue="BCEL-237" type="fix" dev="sebb">non-empty final arrays should be private as they are mutable.</action> <action issue="BCEL-230" type="update" dev="britter">Document the Java platform requirement clearly and early.</action> <action issue="BCEL-243" type="fix">Type.getType() needs to understand TypeVariableSignature(s).</action> Modified: commons/proper/bcel/trunk/src/main/java/org/apache/bcel/generic/InvokeInstruction.java URL: http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/main/java/org/apache/bcel/generic/InvokeInstruction.java?rev=1751083&r1=1751082&r2=1751083&view=diff ============================================================================== --- commons/proper/bcel/trunk/src/main/java/org/apache/bcel/generic/InvokeInstruction.java (original) +++ commons/proper/bcel/trunk/src/main/java/org/apache/bcel/generic/InvokeInstruction.java Sat Jul 2 16:51:15 2016 @@ -21,6 +21,7 @@ import java.util.StringTokenizer; import org.apache.bcel.Const; import org.apache.bcel.classfile.Constant; +import org.apache.bcel.classfile.ConstantCP; import org.apache.bcel.classfile.ConstantPool; /** @@ -90,6 +91,24 @@ public abstract class InvokeInstruction return Type.getReturnTypeSize(signature); } + /** + * This overrides the deprecated version as we know here that the referenced class + * cannot be an array unless something has gone badly wrong. + * may legally be an array. + * * + * @return name of the referenced class/interface + * @throws IllegalArgumentException if the referenced class is an array (this should not happen) + */ + @Override + public String getClassName( final ConstantPoolGen cpg ) { + final ConstantPool cp = cpg.getConstantPool(); + final ConstantCP cmr = (ConstantCP) cp.getConstant(super.getIndex()); + final String className = cp.getConstantString(cmr.getClassIndex(), Const.CONSTANT_Class); + if (className.startsWith("[")) { + throw new IllegalArgumentException("Cannot be used on an array type"); + } + return className.replace('/', '.'); + } /** @return return type of referenced method. */