Return-Path: X-Original-To: apmail-commons-commits-archive@minotaur.apache.org Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 6106A185EE for ; Thu, 13 Aug 2015 21:21:13 +0000 (UTC) Received: (qmail 18762 invoked by uid 500); 13 Aug 2015 21:21:13 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 18677 invoked by uid 500); 13 Aug 2015 21:21:13 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 18668 invoked by uid 99); 13 Aug 2015 21:21:13 -0000 Received: from eris.apache.org (HELO hades.apache.org) (140.211.11.105) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 13 Aug 2015 21:21:13 +0000 Received: from hades.apache.org (localhost [127.0.0.1]) by hades.apache.org (ASF Mail Server at hades.apache.org) with ESMTP id 11F4DAC0734 for ; Thu, 13 Aug 2015 21:21:13 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: 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/ Date: Thu, 13 Aug 2015 21:21:12 -0000 To: commits@commons.apache.org From: sebb@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20150813212113.11F4DAC0734@hades.apache.org> 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 type attribute can be add,u + Need to check for an empty InstructionList Inconsistent toString() results long type instructions are not searched by InstructionFinder using regular expression Update Java requirement from 5 to 7 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