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 4e585413 Replace magic number with constant
4e585413 is described below
commit 4e5854135e71bbcc369e0c15a12db143272a4919
Author: Gary David Gregory (Code signing key) <[email protected]>
AuthorDate: Tue Nov 15 09:00:35 2022 -0500
Replace magic number with constant
- Nicer format for exception message
- Javadoc
---
src/main/java/org/apache/bcel/classfile/Code.java | 15 +++++++++++----
1 file changed, 11 insertions(+), 4 deletions(-)
diff --git a/src/main/java/org/apache/bcel/classfile/Code.java
b/src/main/java/org/apache/bcel/classfile/Code.java
index 6afb44f9..38fe68a7 100644
--- a/src/main/java/org/apache/bcel/classfile/Code.java
+++ b/src/main/java/org/apache/bcel/classfile/Code.java
@@ -48,9 +48,12 @@ public final class Code extends Attribute {
/**
* Initialize from another object. Note that both objects use the same
references (shallow copy). Use copy() for a
* physical copy.
+ *
+ * @param code The source Code.
*/
- public Code(final Code c) {
- this(c.getNameIndex(), c.getLength(), c.getMaxStack(),
c.getMaxLocals(), c.getCode(), c.getExceptionTable(), c.getAttributes(),
c.getConstantPool());
+ public Code(final Code code) {
+ this(code.getNameIndex(), code.getLength(), code.getMaxStack(),
code.getMaxLocals(), code.getCode(), code.getExceptionTable(),
code.getAttributes(),
+ code.getConstantPool());
}
/**
@@ -63,8 +66,9 @@ public final class Code extends Attribute {
// Initialize with some default values which will be overwritten later
this(nameIndex, length, file.readUnsignedShort(),
file.readUnsignedShort(), (byte[]) null, (CodeException[]) null, (Attribute[])
null, constantPool);
final int codeLength = file.readInt();
- if (codeLength < 1 || codeLength > 65535) {
- throw new ClassFormatException("Invalid length " + codeLength + "
for Code attribute. Must be greater than zero and less than 65536.");
+ if (codeLength < 1 || codeLength > Const.MAX_SHORT) {
+ throw new ClassFormatException(
+ String.format("Invalid length %,d for Code attribute. Must
be greater than zero and less than %,d.", codeLength, Const.MAX_SHORT));
}
code = new byte[codeLength]; // Read byte code
file.readFully(code);
@@ -299,6 +303,9 @@ public final class Code extends Attribute {
}
/**
+ * Converts this object to a String.
+ *
+ * @param verbose Provides verbose output when true.
* @return String representation of code chunk.
*/
public String toString(final boolean verbose) {