This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-bcel.git


The following commit(s) were added to refs/heads/master by this push:
     new b2dcf8e  BCEL-330 (#35)
b2dcf8e is described below

commit b2dcf8ed70ae66b8702dd0ce60a815d004490ca0
Author: Mark Roberts <markr...@users.noreply.github.com>
AuthorDate: Fri Oct 11 08:43:46 2019 -1000

    BCEL-330 (#35)
    
    * fix BCEL-329 attribute duplication
    
    * fix BCEL-330 remove references to Constants
---
 .../org/apache/bcel/classfile/CodeException.java   |  3 +-
 .../org/apache/bcel/classfile/LocalVariable.java   |  3 +-
 .../java/org/apache/bcel/generic/MethodGen.java    | 40 +++++++++++++---------
 src/main/java/org/apache/bcel/util/Class2HTML.java |  3 +-
 .../bcel/verifier/statics/Pass2Verifier.java       |  3 +-
 .../structurals/UninitializedObjectType.java       |  3 +-
 6 files changed, 29 insertions(+), 26 deletions(-)

diff --git a/src/main/java/org/apache/bcel/classfile/CodeException.java 
b/src/main/java/org/apache/bcel/classfile/CodeException.java
index c79cc9b..f51cde1 100644
--- a/src/main/java/org/apache/bcel/classfile/CodeException.java
+++ b/src/main/java/org/apache/bcel/classfile/CodeException.java
@@ -22,7 +22,6 @@ import java.io.DataOutputStream;
 import java.io.IOException;
 
 import org.apache.bcel.Const;
-import org.apache.bcel.Constants;
 
 /**
  * This class represents an entry in the exception table of the <em>Code</em>
@@ -31,7 +30,7 @@ import org.apache.bcel.Constants;
  *
  * @see     Code
  */
-public final class CodeException implements Cloneable, Node, Constants {
+public final class CodeException implements Cloneable, Node {
 
     private int start_pc; // Range in the code the exception handler is
     private int end_pc; // active. start_pc is inclusive, end_pc exclusive
diff --git a/src/main/java/org/apache/bcel/classfile/LocalVariable.java 
b/src/main/java/org/apache/bcel/classfile/LocalVariable.java
index 7ad67e4..e8c6315 100644
--- a/src/main/java/org/apache/bcel/classfile/LocalVariable.java
+++ b/src/main/java/org/apache/bcel/classfile/LocalVariable.java
@@ -22,7 +22,6 @@ import java.io.DataOutputStream;
 import java.io.IOException;
 
 import org.apache.bcel.Const;
-import org.apache.bcel.Constants;
 
 /**
  * This class represents a local variable within a method. It contains its
@@ -37,7 +36,7 @@ import org.apache.bcel.Constants;
  * @see     LocalVariableTable
  * @see     LocalVariableTypeTable
  */
-public final class LocalVariable implements Cloneable, Node, Constants {
+public final class LocalVariable implements Cloneable, Node {
 
     private int start_pc; // Range in which the variable is valid
     private int length;
diff --git a/src/main/java/org/apache/bcel/generic/MethodGen.java 
b/src/main/java/org/apache/bcel/generic/MethodGen.java
index b0743e3..958e28d 100644
--- a/src/main/java/org/apache/bcel/generic/MethodGen.java
+++ b/src/main/java/org/apache/bcel/generic/MethodGen.java
@@ -599,27 +599,33 @@ public class MethodGen extends FieldGenOrMethodGen {
     /**
      * @since 6.0
      */
-    public void addAnnotationsAsAttribute(final ConstantPoolGen cp) {
-          final Attribute[] attrs = 
AnnotationEntryGen.getAnnotationAttributes(cp, super.getAnnotationEntries());
+    public Attribute[] addAnnotationsAsAttribute(final ConstantPoolGen cp) {
+        final Attribute[] attrs = 
AnnotationEntryGen.getAnnotationAttributes(cp, super.getAnnotationEntries());
         for (final Attribute attr : attrs) {
             addAttribute(attr);
         }
-      }
+        return attrs;
+    }
 
     /**
      * @since 6.0
      */
-      public void addParameterAnnotationsAsAttribute(final ConstantPoolGen cp) 
{
-          if (!hasParameterAnnotations) {
-              return;
-          }
-          final Attribute[] attrs = 
AnnotationEntryGen.getParameterAnnotationAttributes(cp,param_annotations);
-          if (attrs != null) {
-              for (final Attribute attr : attrs) {
-                  addAttribute(attr);
-              }
-          }
-      }
+    public Attribute[] addParameterAnnotationsAsAttribute(final 
ConstantPoolGen cp) {
+        if (!hasParameterAnnotations) {
+            return new Attribute[0];
+        }
+        final Attribute[] attrs = 
AnnotationEntryGen.getParameterAnnotationAttributes(cp, param_annotations);
+        for (final Attribute attr : attrs) {
+            addAttribute(attr);
+        }
+        return attrs;
+    }
+
+    private void removeAttributes(Attribute[] attrs) {
+        for (final Attribute attr : attrs) {
+            removeAttribute(attr);
+        }
+    }
 
 
     /**
@@ -681,8 +687,8 @@ public class MethodGen extends FieldGenOrMethodGen {
                     max_stack, max_locals, byte_code, c_exc, code_attrs, 
_cp.getConstantPool());
             addAttribute(code);
         }
-        addAnnotationsAsAttribute(_cp);
-        addParameterAnnotationsAsAttribute(_cp);
+        Attribute[] annotations = addAnnotationsAsAttribute(_cp);
+        Attribute[] parameterAnnotations = 
addParameterAnnotationsAsAttribute(_cp);
         ExceptionTable et = null;
         if (throws_vec.size() > 0) {
             addAttribute(et = getExceptionTable(_cp));
@@ -706,6 +712,8 @@ public class MethodGen extends FieldGenOrMethodGen {
         if (et != null) {
             removeAttribute(et);
         }
+        removeAttributes(annotations);
+        removeAttributes(parameterAnnotations);
         return m;
     }
 
diff --git a/src/main/java/org/apache/bcel/util/Class2HTML.java 
b/src/main/java/org/apache/bcel/util/Class2HTML.java
index 1a34723..e652665 100644
--- a/src/main/java/org/apache/bcel/util/Class2HTML.java
+++ b/src/main/java/org/apache/bcel/util/Class2HTML.java
@@ -25,7 +25,6 @@ import java.util.HashSet;
 import java.util.Set;
 
 import org.apache.bcel.Const;
-import org.apache.bcel.Constants;
 import org.apache.bcel.classfile.Attribute;
 import org.apache.bcel.classfile.ClassParser;
 import org.apache.bcel.classfile.ConstantPool;
@@ -53,7 +52,7 @@ import org.apache.bcel.classfile.Utility;
  * the Code frame.
  *
  */
-public class Class2HTML implements Constants {
+public class Class2HTML {
 
     private final JavaClass java_class; // current class object
     private final String dir;
diff --git a/src/main/java/org/apache/bcel/verifier/statics/Pass2Verifier.java 
b/src/main/java/org/apache/bcel/verifier/statics/Pass2Verifier.java
index fe79b22..e350657 100644
--- a/src/main/java/org/apache/bcel/verifier/statics/Pass2Verifier.java
+++ b/src/main/java/org/apache/bcel/verifier/statics/Pass2Verifier.java
@@ -25,7 +25,6 @@ import java.util.Map;
 import java.util.Set;
 
 import org.apache.bcel.Const;
-import org.apache.bcel.Constants;
 import org.apache.bcel.Repository;
 import org.apache.bcel.classfile.Attribute;
 import org.apache.bcel.classfile.ClassFormatException;
@@ -82,7 +81,7 @@ import 
org.apache.bcel.verifier.exc.LocalVariableInfoInconsistentException;
  *
  * @see #do_verify()
  */
-public final class Pass2Verifier extends PassVerifier implements Constants {
+public final class Pass2Verifier extends PassVerifier {
 
     /**
      * The LocalVariableInfo instances used by Pass3bVerifier.
diff --git 
a/src/main/java/org/apache/bcel/verifier/structurals/UninitializedObjectType.java
 
b/src/main/java/org/apache/bcel/verifier/structurals/UninitializedObjectType.java
index 78fe4cc..4b8f637 100644
--- 
a/src/main/java/org/apache/bcel/verifier/structurals/UninitializedObjectType.java
+++ 
b/src/main/java/org/apache/bcel/verifier/structurals/UninitializedObjectType.java
@@ -19,7 +19,6 @@ package org.apache.bcel.verifier.structurals;
 
 
 import org.apache.bcel.Const;
-import org.apache.bcel.Constants;
 import org.apache.bcel.generic.ObjectType;
 import org.apache.bcel.generic.ReferenceType;
 
@@ -29,7 +28,7 @@ import org.apache.bcel.generic.ReferenceType;
  * more details.
  *
  */
-public class UninitializedObjectType extends ReferenceType implements 
Constants {
+public class UninitializedObjectType extends ReferenceType {
 
     /** The "initialized" version. */
     private final ObjectType initialized;

Reply via email to