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 2022/11/21 15:53:04 UTC

[commons-bcel] branch master updated (a4bf0768 -> d3209d93)

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

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


    from a4bf0768 Javadoc
     new 6013bcf4 Better exception messages
     new 99ef9eff Javadoc
     new d3209d93 org.apache.bcel.classfile.CodeException constructors now throw ClassFormatException on invalid input

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 src/changes/changes.xml                            |  3 +-
 .../org/apache/bcel/classfile/CodeException.java   | 64 +++++++++++++++++-----
 src/main/java/org/apache/bcel/util/Args.java       |  6 +-
 3 files changed, 54 insertions(+), 19 deletions(-)


[commons-bcel] 01/03: Better exception messages

Posted by gg...@apache.org.
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

commit 6013bcf41020e191c0c8f017b906832bbf8338f9
Author: Gary David Gregory (Code signing key) <gg...@apache.org>
AuthorDate: Mon Nov 21 10:43:22 2022 -0500

    Better exception messages
---
 src/main/java/org/apache/bcel/util/Args.java | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/main/java/org/apache/bcel/util/Args.java b/src/main/java/org/apache/bcel/util/Args.java
index be385606..623eb655 100644
--- a/src/main/java/org/apache/bcel/util/Args.java
+++ b/src/main/java/org/apache/bcel/util/Args.java
@@ -78,10 +78,10 @@ public class Args {
      */
     public static int requireU2(final int value, final int min, final int max, final String message) {
         if (max > Const.MAX_SHORT) {
-            throw new IllegalArgumentException(String.format("Programming error: max %,d > %,d", max, Const.MAX_SHORT));
+            throw new IllegalArgumentException(String.format("%s programming error: max %,d > %,d", message, max, Const.MAX_SHORT));
         }
         if (min < 0) {
-            throw new IllegalArgumentException(String.format("Programming error: min %,d < 0", min));
+            throw new IllegalArgumentException(String.format("%s programming error: min %,d < 0", message, min));
         }
         if (value < min || value > max) {
             throw new ClassFormatException(String.format("%s [Value out of range (%,d - %,d) for type u2: %,d]", message, min, Const.MAX_SHORT, value));
@@ -122,7 +122,7 @@ public class Args {
      */
     public static int requireU4(final int value, final int min, final String message) {
         if (min < 0) {
-            throw new IllegalArgumentException(String.format("Programming error: min %,d < 0", min));
+            throw new IllegalArgumentException(String.format("%s programming error: min %,d < 0", message, min));
         }
         if (value < min) {
             throw new ClassFormatException(


[commons-bcel] 03/03: org.apache.bcel.classfile.CodeException constructors now throw ClassFormatException on invalid input

Posted by gg...@apache.org.
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

commit d3209d933ffdbaa1406e6c0b51125852a9c05f76
Author: Gary David Gregory (Code signing key) <gg...@apache.org>
AuthorDate: Mon Nov 21 10:53:00 2022 -0500

    org.apache.bcel.classfile.CodeException constructors now throw
    ClassFormatException on invalid input
---
 src/changes/changes.xml                            |  3 ++-
 .../org/apache/bcel/classfile/CodeException.java   | 29 +++++++++++++++++++---
 2 files changed, 27 insertions(+), 5 deletions(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 30a26c71..9a9f46c2 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -97,8 +97,9 @@ The <action> type attribute can be add,update,fix,remove.
       <action                  type="fix" dev="ggregory" due-to="Gary Gregory">org.apache.bcel.classfile.ConstantInvokeDynamic.ConstantInvokeDynamic(DataInput).</action>
       <action                  type="fix" dev="ggregory" due-to="Gary Gregory">org.apache.bcel.util.ClassPath hashCode() and equals() don't match.</action>
       <action                  type="fix" dev="markt" due-to="OSS-Fuzz">org.apache.bcel.classfile.StackMapType constructors now throw ClassFormatException on invalid input.</action>
-      <action                  type="add" dev="ggregory" due-to="nbauma109, Gary Gregory">Code coverage and bug fixes for bcelifier #171.</action>
+      <action                  type="fix" dev="ggregory" due-to="nbauma109, Gary Gregory">Code coverage and bug fixes for bcelifier #171.</action>
       <action                  type="fix" dev="markt" due-to="Mark Thomas, Gary Gregory">org.apache.bcel.classfile.Attribute constructors now throw ClassFormatException on invalid length input.</action>
+      <action                  type="fix" dev="ggregory" due-to="Gary Gregory">org.apache.bcel.classfile.CodeException constructors now throw ClassFormatException on invalid input.</action>      
       <!-- UPDATE -->
       <action                  type="update" dev="ggregory" due-to="Gary Gregory">Bump spotbugs-maven-plugin from 4.7.2.2 to 4.7.3.0 #167.</action>
       <action                  type="update" dev="ggregory" due-to="Dependabot">Bump jmh.version from 1.35 to 1.36 #170.</action>
diff --git a/src/main/java/org/apache/bcel/classfile/CodeException.java b/src/main/java/org/apache/bcel/classfile/CodeException.java
index 54725fc8..d5b16ce6 100644
--- a/src/main/java/org/apache/bcel/classfile/CodeException.java
+++ b/src/main/java/org/apache/bcel/classfile/CodeException.java
@@ -22,11 +22,32 @@ import java.io.IOException;
 
 import org.apache.bcel.Const;
 import org.apache.bcel.Constants;
+import org.apache.bcel.util.Args;
 
 /**
  * This class represents an entry in the exception table of the <em>Code</em> attribute and is used only there. It
  * contains a range in which a particular exception handler is active.
  *
+ * <pre>
+ * Code_attribute {
+ *   u2 attribute_name_index;
+ *   u4 attribute_length;
+ *   u2 max_stack;
+ *   u2 max_locals;
+ *   u4 code_length;
+ *   u1 code[code_length];
+ *   u2 exception_table_length;
+ *   {
+ *     u2 start_pc;
+ *     u2 end_pc;
+ *     u2 handler_pc;
+ *     u2 catch_type;
+ *   } exception_table[exception_table_length];
+ *   u2 attributes_count;
+ *   attribute_info attributes[attributes_count];
+ * }
+ * </pre>
+ *
  * @see Code
  */
 public final class CodeException implements Cloneable, Node, Constants {
@@ -81,10 +102,10 @@ public final class CodeException implements Cloneable, Node, Constants {
      *        caught.
      */
     public CodeException(final int startPc, final int endPc, final int handlerPc, final int catchType) {
-        this.startPc = startPc;
-        this.endPc = endPc;
-        this.handlerPc = handlerPc;
-        this.catchType = catchType;
+        this.startPc = Args.requireU2(startPc, "startPc");
+        this.endPc = Args.requireU2(endPc, "endPc");
+        this.handlerPc = Args.requireU2(handlerPc, "handlerPc");
+        this.catchType = Args.requireU2(catchType, "catchType");
     }
 
     /**


[commons-bcel] 02/03: Javadoc

Posted by gg...@apache.org.
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

commit 99ef9eff8d7b85ce83e8aacefce3089be53edd2e
Author: Gary David Gregory (Code signing key) <gg...@apache.org>
AuthorDate: Mon Nov 21 10:46:14 2022 -0500

    Javadoc
---
 .../org/apache/bcel/classfile/CodeException.java   | 35 +++++++++++++++-------
 1 file changed, 24 insertions(+), 11 deletions(-)

diff --git a/src/main/java/org/apache/bcel/classfile/CodeException.java b/src/main/java/org/apache/bcel/classfile/CodeException.java
index c9b6f28c..54725fc8 100644
--- a/src/main/java/org/apache/bcel/classfile/CodeException.java
+++ b/src/main/java/org/apache/bcel/classfile/CodeException.java
@@ -35,25 +35,34 @@ public final class CodeException implements Cloneable, Node, Constants {
      * Empty array.
      */
     static final CodeException[] EMPTY_CODE_EXCEPTION_ARRAY = {};
-    private int startPc; // Range in the code the exception handler is
-    private int endPc; // active. startPc is inclusive, endPc exclusive
-    private int handlerPc; /*
-                            * Starting address of exception handler, i.e., an offset from start of code.
-                            */
 
-    private int catchType; /*
-                            * If this is zero the handler catches any exception, otherwise it points to the exception class which is to be caught.
-                            */
+    /** Range in the code the exception handler. */
+    private int startPc;
+
+    /** active. startPc is inclusive, endPc exclusive. */
+    private int endPc;
+
+    /**
+     * Starting address of exception handler, i.e., an offset from start of code.
+     */
+    private int handlerPc;
+
+    /*
+     * If this is zero the handler catches any exception, otherwise it points to the exception class which is to be caught.
+     */
+    private int catchType;
 
     /**
-     * Initialize from another object.
+     * Constructs a new instance from another instance.
+     *
+     * @param c Source for copying.
      */
     public CodeException(final CodeException c) {
         this(c.getStartPC(), c.getEndPC(), c.getHandlerPC(), c.getCatchType());
     }
 
     /**
-     * Construct object from file stream.
+     * Constructs a new instance from a DataInput.
      *
      * @param file Input stream
      * @throws IOException if an I/O error occurs.
@@ -63,6 +72,8 @@ public final class CodeException implements Cloneable, Node, Constants {
     }
 
     /**
+     * Constructs a new instance.
+     *
      * @param startPc Range in the code the exception handler is active, startPc is inclusive while
      * @param endPc is exclusive
      * @param handlerPc Starting address of exception handler, i.e., an offset from start of code.
@@ -100,7 +111,7 @@ public final class CodeException implements Cloneable, Node, Constants {
     }
 
     /**
-     * Dump code exception to file stream in binary format.
+     * Dumps code exception to file stream in binary format.
      *
      * @param file Output file stream
      * @throws IOException if an I/O error occurs.
@@ -181,6 +192,8 @@ public final class CodeException implements Cloneable, Node, Constants {
     }
 
     /**
+     * @param cp constant pool source.
+     * @param verbose Output more if true.
      * @return String representation.
      */
     public String toString(final ConstantPool cp, final boolean verbose) {