You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by br...@apache.org on 2016/07/29 08:10:05 UTC
svn commit: r1754483 - in /commons/proper/bcel/trunk/src: changes/
main/java/org/apache/bcel/classfile/ test/java/org/apache/bcel/classfile/
test/java/org/apache/bcel/data/
Author: britter
Date: Fri Jul 29 08:10:05 2016
New Revision: 1754483
URL: http://svn.apache.org/viewvc?rev=1754483&view=rev
Log:
BCEL-277: Resolving the String representation of a constant throws NoSuchElementException in case of CONSTANT_NameAndType constant. Thanks to Sam Yoon. This also closes #9 from GitHub.
Added:
commons/proper/bcel/trunk/src/test/java/org/apache/bcel/classfile/ConstantPoolTestCase.java
commons/proper/bcel/trunk/src/test/java/org/apache/bcel/data/SimpleClassWithDefaultConstructor.java
Modified:
commons/proper/bcel/trunk/src/changes/changes.xml
commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/ConstantPool.java
Modified: commons/proper/bcel/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/changes/changes.xml?rev=1754483&r1=1754482&r2=1754483&view=diff
==============================================================================
--- commons/proper/bcel/trunk/src/changes/changes.xml [utf-8] (original)
+++ commons/proper/bcel/trunk/src/changes/changes.xml [utf-8] Fri Jul 29 08:10:05 2016
@@ -63,6 +63,7 @@ The <action> type attribute can be add,u
<body>
<release version="6.1" date="tba" description="tba">
+ <action issue="BCEL-277" type="fix" dev="britter" due-to="Sam Yoon">Resolving the String representation of a constant throws NoSuchElementException in case of CONSTANT_NameAndType constant.</action>
</release>
<release version="6.0" date="2016-07-10" description="Apache Commons BCEL 6.0 is a major release supporting the new features
Modified: commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/ConstantPool.java
URL: http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/ConstantPool.java?rev=1754483&r1=1754482&r2=1754483&view=diff
==============================================================================
--- commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/ConstantPool.java (original)
+++ commons/proper/bcel/trunk/src/main/java/org/apache/bcel/classfile/ConstantPool.java Fri Jul 29 08:10:05 2016
@@ -131,7 +131,7 @@ public class ConstantPool implements Clo
case Const.CONSTANT_NameAndType:
str = constantToString(((ConstantNameAndType) c).getNameIndex(),
Const.CONSTANT_Utf8)
- + ":" + constantToString(((ConstantNameAndType) c).getSignatureIndex(),
+ + " " + constantToString(((ConstantNameAndType) c).getSignatureIndex(),
Const.CONSTANT_Utf8);
break;
case Const.CONSTANT_InterfaceMethodref:
@@ -148,7 +148,7 @@ public class ConstantPool implements Clo
str = Const.getMethodHandleName(cmh.getReferenceKind())
+ " " + constantToString(cmh.getReferenceIndex(),
getConstant(cmh.getReferenceIndex()).getTag());
- break;
+ break;
case Const.CONSTANT_MethodType:
final ConstantMethodType cmt = (ConstantMethodType) c;
str = constantToString(cmt.getDescriptorIndex(), Const.CONSTANT_Utf8);
@@ -209,7 +209,7 @@ public class ConstantPool implements Clo
}
- /**
+ /**
* Dump constant pool to file stream in binary format.
*
* @param file Output file stream
Added: commons/proper/bcel/trunk/src/test/java/org/apache/bcel/classfile/ConstantPoolTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/test/java/org/apache/bcel/classfile/ConstantPoolTestCase.java?rev=1754483&view=auto
==============================================================================
--- commons/proper/bcel/trunk/src/test/java/org/apache/bcel/classfile/ConstantPoolTestCase.java (added)
+++ commons/proper/bcel/trunk/src/test/java/org/apache/bcel/classfile/ConstantPoolTestCase.java Fri Jul 29 08:10:05 2016
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.bcel.classfile;
+
+import org.apache.bcel.AbstractTestCase;
+import org.apache.bcel.generic.ConstantPoolGen;
+import org.apache.bcel.generic.InstructionHandle;
+import org.apache.bcel.generic.InstructionList;
+import org.apache.bcel.generic.MethodGen;
+import org.junit.Test;
+
+public class ConstantPoolTestCase extends AbstractTestCase {
+ @Test
+ public void testConstantToString() throws ClassNotFoundException {
+ JavaClass clazz = getTestClass(PACKAGE_BASE_NAME + ".data.SimpleClassWithDefaultConstructor");
+ ConstantPoolGen cp = new ConstantPoolGen(clazz.getConstantPool());
+
+ Method[] methods = clazz.getMethods();
+
+ for (Method method : methods) {
+ if (method.getName().equals("<init>")) {
+ for (InstructionHandle instructionHandle : getInstructionHandles(clazz, cp, method)) {
+ System.out.println(instructionHandle.getInstruction().toString(cp.getConstantPool()));
+ }
+ }
+ }
+ }
+
+ private InstructionHandle[] getInstructionHandles(JavaClass clazz, ConstantPoolGen cp, Method method) {
+ MethodGen methodGen = new MethodGen(method, clazz.getClassName(), cp);
+ InstructionList instructionList = methodGen.getInstructionList();
+ return instructionList.getInstructionHandles();
+ }
+}
Added: commons/proper/bcel/trunk/src/test/java/org/apache/bcel/data/SimpleClassWithDefaultConstructor.java
URL: http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/test/java/org/apache/bcel/data/SimpleClassWithDefaultConstructor.java?rev=1754483&view=auto
==============================================================================
--- commons/proper/bcel/trunk/src/test/java/org/apache/bcel/data/SimpleClassWithDefaultConstructor.java (added)
+++ commons/proper/bcel/trunk/src/test/java/org/apache/bcel/data/SimpleClassWithDefaultConstructor.java Fri Jul 29 08:10:05 2016
@@ -0,0 +1,26 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.bcel.data;
+
+public class SimpleClassWithDefaultConstructor {
+
+ public SimpleClassWithDefaultConstructor() {
+ }
+
+}