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) <ggreg...@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);
         }
     }
 

Reply via email to