You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by se...@apache.org on 2015/08/13 23:21:12 UTC
svn commit: r1695781 - in /commons/proper/bcel/trunk/src: changes/
main/java/org/apache/commons/bcel6/generic/
test/java/org/apache/commons/bcel6/ test/java/org/apache/commons/bcel6/data/
Author: sebb
Date: Thu Aug 13 21:21:12 2015
New Revision: 1695781
URL: http://svn.apache.org/r1695781
Log:
BCEL-208 Need to check for an empty InstructionList
Added:
commons/proper/bcel/trunk/src/test/java/org/apache/commons/bcel6/PLSETestCase.java (with props)
commons/proper/bcel/trunk/src/test/java/org/apache/commons/bcel6/data/PLSETestClass.java (with props)
Modified:
commons/proper/bcel/trunk/src/changes/changes.xml
commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/generic/LocalVariableGen.java
commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/generic/MethodGen.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=1695781&r1=1695780&r2=1695781&view=diff
==============================================================================
--- commons/proper/bcel/trunk/src/changes/changes.xml (original)
+++ commons/proper/bcel/trunk/src/changes/changes.xml Thu Aug 13 21:21:12 2015
@@ -63,6 +63,7 @@ The <action> type attribute can be add,u
<body>
<release version="6.0" date="TBA" description="Major release with Java 7 and 8 support">
+ <action issue="BCEL-208" type=fix>Need to check for an empty InstructionList</action>
<action issue="BCEL-212" type="update">Inconsistent toString() results</action>
<action issue="BCEL-217" type="fix">long type instructions are not searched by InstructionFinder using regular expression</action>
<action issue="BCEL-244" type="update" dev="ggregory">Update Java requirement from 5 to 7</action>
Modified: commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/generic/LocalVariableGen.java
URL: http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/generic/LocalVariableGen.java?rev=1695781&r1=1695780&r2=1695781&view=diff
==============================================================================
--- commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/generic/LocalVariableGen.java (original)
+++ commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/generic/LocalVariableGen.java Thu Aug 13 21:21:12 2015
@@ -78,10 +78,14 @@ public class LocalVariableGen implements
* @param cp constant pool
*/
public LocalVariable getLocalVariable( ConstantPoolGen cp ) {
- int start_pc = start.getPosition();
- int length = end.getPosition() - start_pc;
- if (end.getNext() == null) {
- length += end.getInstruction().getLength();
+ int start_pc = 0;
+ int length = 0;
+ if ((start != null) && (end != null)) {
+ start_pc = start.getPosition();
+ length = end.getPosition() - start_pc;
+ if (end.getNext() == null) {
+ length += end.getInstruction().getLength();
+ }
}
int name_index = cp.addUtf8(name);
int signature_index = cp.addUtf8(type.getSignature());
Modified: commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/generic/MethodGen.java
URL: http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/generic/MethodGen.java?rev=1695781&r1=1695780&r2=1695781&view=diff
==============================================================================
--- commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/generic/MethodGen.java (original)
+++ commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/generic/MethodGen.java Thu Aug 13 21:21:12 2015
@@ -360,10 +360,10 @@ public class MethodGen extends FieldGenO
LocalVariableGen[] lg = new LocalVariableGen[size];
variable_vec.toArray(lg);
for (int i = 0; i < size; i++) {
- if (lg[i].getStart() == null) {
+ if ((lg[i].getStart() == null) && (il != null)) {
lg[i].setStart(il.getStart());
}
- if (lg[i].getEnd() == null) {
+ if ((lg[i].getEnd() == null) && (il != null)) {
lg[i].setEnd(il.getEnd());
}
}
Added: commons/proper/bcel/trunk/src/test/java/org/apache/commons/bcel6/PLSETestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/test/java/org/apache/commons/bcel6/PLSETestCase.java?rev=1695781&view=auto
==============================================================================
--- commons/proper/bcel/trunk/src/test/java/org/apache/commons/bcel6/PLSETestCase.java (added)
+++ commons/proper/bcel/trunk/src/test/java/org/apache/commons/bcel6/PLSETestCase.java Thu Aug 13 21:21:12 2015
@@ -0,0 +1,46 @@
+/*
+ * 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.commons.bcel6;
+
+import org.apache.commons.bcel6.classfile.JavaClass;
+import org.apache.commons.bcel6.classfile.Method;
+import org.apache.commons.bcel6.generic.ClassGen;
+import org.apache.commons.bcel6.generic.ConstantPoolGen;
+import org.apache.commons.bcel6.generic.MethodGen;
+import org.apache.commons.bcel6.generic.Type;
+
+public class PLSETestCase extends AbstractTestCase
+{
+ /**
+ * BCEL-208: A couple of methods in MethodGen.java need to test for
+ * an empty instruction list.
+ */
+ public void testB208() throws ClassNotFoundException
+ {
+ JavaClass clazz = getTestClass("org.apache.commons.bcel6.data.PLSETestClass");
+ ClassGen gen = new ClassGen(clazz);
+ ConstantPoolGen pool = gen.getConstantPool();
+ Method m = gen.getMethodAt(1);
+ MethodGen mg = new MethodGen(m, gen.getClassName(), pool);
+ mg.setInstructionList(null);
+ mg.addLocalVariable("local2", Type.INT, null, null);
+ // currently, this will cause null pointer exception
+ mg.getLocalVariableTable(pool);
+ }
+}
Propchange: commons/proper/bcel/trunk/src/test/java/org/apache/commons/bcel6/PLSETestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: commons/proper/bcel/trunk/src/test/java/org/apache/commons/bcel6/data/PLSETestClass.java
URL: http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/test/java/org/apache/commons/bcel6/data/PLSETestClass.java?rev=1695781&view=auto
==============================================================================
--- commons/proper/bcel/trunk/src/test/java/org/apache/commons/bcel6/data/PLSETestClass.java (added)
+++ commons/proper/bcel/trunk/src/test/java/org/apache/commons/bcel6/data/PLSETestClass.java Thu Aug 13 21:21:12 2015
@@ -0,0 +1,28 @@
+/*
+ * 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.commons.bcel6.data;
+
+public class PLSETestClass
+{
+ public void meth1(int arg1)
+ {
+ @SuppressWarnings("unused")
+ int local1 = arg1;
+ }
+}
Propchange: commons/proper/bcel/trunk/src/test/java/org/apache/commons/bcel6/data/PLSETestClass.java
------------------------------------------------------------------------------
svn:eol-style = native