You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2019/10/12 20:55:37 UTC
[commons-bcel] branch master updated: fix BCEL-329 attribute
duplication (#34)
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 57142f1 fix BCEL-329 attribute duplication (#34)
57142f1 is described below
commit 57142f1b2a99f1b691ba430a9cfef50ccd8a6cc0
Author: Mark Roberts <ma...@users.noreply.github.com>
AuthorDate: Sat Oct 12 10:55:31 2019 -1000
fix BCEL-329 attribute duplication (#34)
* fix BCEL-329 attribute duplication
* rewrite fix so don't break binary compatibility
* update changes; enable ability to check for BCEL-329 fix.
---
src/changes/changes.xml | 4 ++
.../java/org/apache/bcel/generic/MethodGen.java | 62 ++++++++++++++++------
2 files changed, 51 insertions(+), 15 deletions(-)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index ca5cb29..19893aa 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -62,6 +62,10 @@ The <action> type attribute can be add,update,fix,remove.
-->
<body>
+ <release version="6.4.2" date="2019-10-XX" description="Bug fix release.">
+ <action issue="BCEL-330" type="update" dev="ggregory" due-to="Mark Roberts">Remove unnecessary references to Constants.</action>
+ <action issue="BCEL-329" type="fix" dev="ggregory" due-to="Gary Gregory, Mark Roberts">MethodGen duplicates some attributes.</action>
+ </release>
<release version="6.4.1" date="2019-09-26" description="Bug fix release.">
<action issue="BCEL-328" type="fix" dev="ggregory" due-to="Gary Gregory, Mark Roberts">java.util.EmptyStackException at org.apache.bcel.classfile.DescendingVisitor.visitModule (DescendingVisitor.java:592).</action>
<action type="update" dev="ggregory" due-to="Gary Gregory">Update build from Checkstyle Maven Plugin 3.0.0 to 3.1.0.</action>
diff --git a/src/main/java/org/apache/bcel/generic/MethodGen.java b/src/main/java/org/apache/bcel/generic/MethodGen.java
index b0743e3..fac52de 100644
--- a/src/main/java/org/apache/bcel/generic/MethodGen.java
+++ b/src/main/java/org/apache/bcel/generic/MethodGen.java
@@ -600,26 +600,56 @@ public class MethodGen extends FieldGenOrMethodGen {
* @since 6.0
*/
public void addAnnotationsAsAttribute(final ConstantPoolGen cp) {
- final Attribute[] attrs = AnnotationEntryGen.getAnnotationAttributes(cp, super.getAnnotationEntries());
+ final Attribute[] attrs = AnnotationEntryGen.getAnnotationAttributes(cp, super.getAnnotationEntries());
for (final Attribute attr : attrs) {
addAttribute(attr);
}
- }
+ }
/**
* @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 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);
+ }
+ }
+ }
+
+ private Attribute[] addRuntimeAnnotationsAsAttribute(final ConstantPoolGen cp) {
+ final Attribute[] attrs = AnnotationEntryGen.getAnnotationAttributes(cp, super.getAnnotationEntries());
+ for (final Attribute attr : attrs) {
+ addAttribute(attr);
+ }
+ return attrs;
+ }
+
+ private Attribute[] addRuntimeParameterAnnotationsAsAttribute(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;
+ }
+
+ /**
+ * Would prefer to make this private, but need a way to test if client is
+ * using BCEL version 6.4.2 or later that contains fix for BCEL-329.
+ * @since 6.4.2
+ */
+ public void removeRuntimeAttributes(Attribute[] attrs) {
+ for (final Attribute attr : attrs) {
+ removeAttribute(attr);
+ }
+ }
/**
@@ -681,8 +711,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 = addRuntimeAnnotationsAsAttribute(_cp);
+ Attribute[] parameterAnnotations = addRuntimeParameterAnnotationsAsAttribute(_cp);
ExceptionTable et = null;
if (throws_vec.size() > 0) {
addAttribute(et = getExceptionTable(_cp));
@@ -706,6 +736,8 @@ public class MethodGen extends FieldGenOrMethodGen {
if (et != null) {
removeAttribute(et);
}
+ removeRuntimeAttributes(annotations);
+ removeRuntimeAttributes(parameterAnnotations);
return m;
}