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/15 12:20:04 UTC

[commons-bcel] branch master updated (a68b26b2 -> eb80c2fb)

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 a68b26b2 Use try-with-resources
     new 27d756d7 Throw ClassFormatException instead of IAE and ISE
     new eb80c2fb Add org.apache.bcel.classfile.ClassFormatException.ClassFormatException(Throwable)

The 2 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                            |  2 ++
 .../bcel/classfile/AnnotationElementValue.java     |  2 +-
 .../apache/bcel/classfile/ArrayElementValue.java   |  2 +-
 .../bcel/classfile/ClassFormatException.java       | 36 +++++++++++++++++++---
 .../org/apache/bcel/classfile/ClassParser.java     |  2 --
 .../org/apache/bcel/classfile/ElementValue.java    | 10 ++----
 .../apache/bcel/classfile/EnumElementValue.java    |  2 +-
 .../apache/bcel/classfile/SimpleElementValue.java  |  2 +-
 8 files changed, 40 insertions(+), 18 deletions(-)


[commons-bcel] 01/02: Throw ClassFormatException instead of IAE and ISE

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 27d756d79d196014a954594ba9d01ed2f5cde306
Author: Gary David Gregory (Code signing key) <gg...@apache.org>
AuthorDate: Tue Nov 15 07:17:00 2022 -0500

    Throw ClassFormatException instead of IAE and ISE
---
 .../java/org/apache/bcel/classfile/AnnotationElementValue.java |  2 +-
 src/main/java/org/apache/bcel/classfile/ArrayElementValue.java |  2 +-
 src/main/java/org/apache/bcel/classfile/ClassParser.java       |  2 --
 src/main/java/org/apache/bcel/classfile/ElementValue.java      | 10 ++--------
 src/main/java/org/apache/bcel/classfile/EnumElementValue.java  |  2 +-
 .../java/org/apache/bcel/classfile/SimpleElementValue.java     |  2 +-
 6 files changed, 6 insertions(+), 14 deletions(-)

diff --git a/src/main/java/org/apache/bcel/classfile/AnnotationElementValue.java b/src/main/java/org/apache/bcel/classfile/AnnotationElementValue.java
index 006999ad..6eb92ed8 100644
--- a/src/main/java/org/apache/bcel/classfile/AnnotationElementValue.java
+++ b/src/main/java/org/apache/bcel/classfile/AnnotationElementValue.java
@@ -29,7 +29,7 @@ public class AnnotationElementValue extends ElementValue {
     public AnnotationElementValue(final int type, final AnnotationEntry annotationEntry, final ConstantPool cpool) {
         super(type, cpool);
         if (type != ANNOTATION) {
-            throw new IllegalArgumentException("Only element values of type annotation can be built with this ctor - type specified: " + type);
+            throw new ClassFormatException("Only element values of type annotation can be built with this ctor - type specified: " + type);
         }
         this.annotationEntry = annotationEntry;
     }
diff --git a/src/main/java/org/apache/bcel/classfile/ArrayElementValue.java b/src/main/java/org/apache/bcel/classfile/ArrayElementValue.java
index 278da523..13d46264 100644
--- a/src/main/java/org/apache/bcel/classfile/ArrayElementValue.java
+++ b/src/main/java/org/apache/bcel/classfile/ArrayElementValue.java
@@ -29,7 +29,7 @@ public class ArrayElementValue extends ElementValue {
     public ArrayElementValue(final int type, final ElementValue[] datums, final ConstantPool cpool) {
         super(type, cpool);
         if (type != ARRAY) {
-            throw new IllegalArgumentException("Only element values of type array can be built with this ctor - type specified: " + type);
+            throw new ClassFormatException("Only element values of type array can be built with this ctor - type specified: " + type);
         }
         this.elementValues = datums;
     }
diff --git a/src/main/java/org/apache/bcel/classfile/ClassParser.java b/src/main/java/org/apache/bcel/classfile/ClassParser.java
index 4b92ed9b..6de11dd4 100644
--- a/src/main/java/org/apache/bcel/classfile/ClassParser.java
+++ b/src/main/java/org/apache/bcel/classfile/ClassParser.java
@@ -155,8 +155,6 @@ public final class ClassParser {
             // System.err.println(bytes + " extra bytes: " + Utility.toHexString(buf));
             // }
             // }
-        } catch (IllegalArgumentException e) {
-            throw new ClassFormatException(e.getMessage(), e);
         } finally {
             // Read everything of interest, so close the file
             if (fileOwned) {
diff --git a/src/main/java/org/apache/bcel/classfile/ElementValue.java b/src/main/java/org/apache/bcel/classfile/ElementValue.java
index 44a983ee..5b0d2aab 100644
--- a/src/main/java/org/apache/bcel/classfile/ElementValue.java
+++ b/src/main/java/org/apache/bcel/classfile/ElementValue.java
@@ -25,20 +25,14 @@ import java.io.IOException;
  * @since 6.0
  */
 public abstract class ElementValue {
-    public static final byte STRING = 's';
 
+    public static final byte STRING = 's';
     public static final byte ENUM_CONSTANT = 'e';
-
     public static final byte CLASS = 'c';
-
     public static final byte ANNOTATION = '@';
-
     public static final byte ARRAY = '[';
-
     public static final byte PRIMITIVE_INT = 'I';
-
     public static final byte PRIMITIVE_BYTE = 'B';
-
     public static final byte PRIMITIVE_CHAR = 'C';
     public static final byte PRIMITIVE_DOUBLE = 'D';
     public static final byte PRIMITIVE_FLOAT = 'F';
@@ -79,7 +73,7 @@ public abstract class ElementValue {
             return new ArrayElementValue(ARRAY, evalues, cpool);
 
         default:
-            throw new IllegalArgumentException("Unexpected element value kind in annotation: " + type);
+            throw new ClassFormatException("Unexpected element value kind in annotation: " + type);
         }
     }
 
diff --git a/src/main/java/org/apache/bcel/classfile/EnumElementValue.java b/src/main/java/org/apache/bcel/classfile/EnumElementValue.java
index cfc24863..95888d06 100644
--- a/src/main/java/org/apache/bcel/classfile/EnumElementValue.java
+++ b/src/main/java/org/apache/bcel/classfile/EnumElementValue.java
@@ -31,7 +31,7 @@ public class EnumElementValue extends ElementValue {
     public EnumElementValue(final int type, final int typeIdx, final int valueIdx, final ConstantPool cpool) {
         super(type, cpool);
         if (type != ENUM_CONSTANT) {
-            throw new IllegalArgumentException("Only element values of type enum can be built with this ctor - type specified: " + type);
+            throw new ClassFormatException("Only element values of type enum can be built with this ctor - type specified: " + type);
         }
         this.typeIdx = typeIdx;
         this.valueIdx = valueIdx;
diff --git a/src/main/java/org/apache/bcel/classfile/SimpleElementValue.java b/src/main/java/org/apache/bcel/classfile/SimpleElementValue.java
index 0a1096ba..00d10c51 100644
--- a/src/main/java/org/apache/bcel/classfile/SimpleElementValue.java
+++ b/src/main/java/org/apache/bcel/classfile/SimpleElementValue.java
@@ -49,7 +49,7 @@ public class SimpleElementValue extends ElementValue {
             dos.writeShort(getIndex());
             break;
         default:
-            throw new IllegalStateException("SimpleElementValue doesnt know how to write out type " + type);
+            throw new ClassFormatException("SimpleElementValue doesnt know how to write out type " + type);
         }
     }
 


[commons-bcel] 02/02: Add org.apache.bcel.classfile.ClassFormatException.ClassFormatException(Throwable)

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 eb80c2fb9504e01751cd7a40a52cb840a7f1fb69
Author: Gary David Gregory (Code signing key) <gg...@apache.org>
AuthorDate: Tue Nov 15 07:19:59 2022 -0500

    Add org.apache.bcel.classfile.ClassFormatException.ClassFormatException(Throwable)
---
 src/changes/changes.xml                            |  2 ++
 .../bcel/classfile/ClassFormatException.java       | 36 +++++++++++++++++++---
 2 files changed, 34 insertions(+), 4 deletions(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 1780b2bf..17d6a984 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -63,6 +63,8 @@ The <action> type attribute can be add,update,fix,remove.
 
   <body>
     <release version="6.6.2" date="20YY-MM-DD" description="Maintenance and bug fix release.">
+      <!-- ADD -->
+      <action                  type="add" dev="ggregory" due-to="Gary Gregory">Add org.apache.bcel.classfile.ClassFormatException.ClassFormatException(Throwable).</action>
       <!-- FIX -->
       <action                  type="fix" dev="ggregory" due-to="nbauma109, Gary Gregory">Typo in SimpleElementValue error message #161.</action>
       <action                  type="fix" dev="ggregory" due-to="Mark Roberts, Gary Gregory">Fix code duplication in org.apache.bcel.verifier.structurals.ExceptionHandlers.ExceptionHandlers(MethodGen).</action>
diff --git a/src/main/java/org/apache/bcel/classfile/ClassFormatException.java b/src/main/java/org/apache/bcel/classfile/ClassFormatException.java
index adcef10c..ad8cb185 100644
--- a/src/main/java/org/apache/bcel/classfile/ClassFormatException.java
+++ b/src/main/java/org/apache/bcel/classfile/ClassFormatException.java
@@ -17,24 +17,52 @@
 package org.apache.bcel.classfile;
 
 /**
- * Thrown when the BCEL attempts to read a class file and determines that a class is malformed or otherwise cannot be
- * interpreted as a class file.
+ * Thrown when the BCEL attempts to read a class file and determines that a class is malformed or otherwise cannot be interpreted as a class file.
  */
 public class ClassFormatException extends RuntimeException {
 
     private static final long serialVersionUID = -3569097343160139969L;
 
+    /**
+     * Constructs a new instance with {@code null} as its detail message. The cause is not initialized, and may subsequently be initialized by a call to
+     * {@link #initCause}.
+     */
     public ClassFormatException() {
     }
 
-    public ClassFormatException(final String s) {
-        super(s);
+    /**
+     * Constructs a new instance with the specified detail message. The cause is not initialized, and may subsequently be initialized by a call to
+     * {@link #initCause}.
+     *
+     * @param message the detail message. The detail message is saved for later retrieval by the {@link #getMessage()} method.
+     */
+    public ClassFormatException(final String message) {
+        super(message);
     }
 
     /**
+     * Constructs a new instance with the specified detail message and cause.
+     * <p>
+     * Note that the detail message associated with {@code cause} is <i>not</i> automatically incorporated in this runtime exception's detail message.
+     *
+     * @param message the detail message (which is saved for later retrieval by the {@link #getMessage()} method).
+     * @param cause   the cause (which is saved for later retrieval by the {@link #getCause()} method). (A {@code null} value is permitted, and indicates that
+     *                the cause is nonexistent or unknown.)
      * @since 6.0
      */
     public ClassFormatException(final String message, final Throwable cause) {
         super(message, cause);
     }
+
+    /**
+     * Constructs a new instance with the specified cause and a detail message of {@code (cause==null ? null : cause.toString())} (which typically contains the
+     * class and detail message of {@code cause}). This constructor is useful for runtime exceptions that are little more than wrappers for other throwables.
+     *
+     * @param cause the cause (which is saved for later retrieval by the {@link #getCause()} method). (A {@code null} value is permitted, and indicates that the
+     *              cause is nonexistent or unknown.)
+     * @since 6.6.2
+     */
+    public ClassFormatException(final Throwable cause) {
+        super(cause);
+    }
 }