garydgregory commented on code in PR #405:
URL: https://github.com/apache/commons-bcel/pull/405#discussion_r1938335256


##########
src/main/java/org/apache/bcel/classfile/Attribute.java:
##########
@@ -18,6 +18,7 @@
  */
 package org.apache.bcel.classfile;
 
+import java.security.InvalidParameterException;

Review Comment:
   This change has nothing to do with JCA or JCE, so 
`java.security.InvalidParameterException` is the wrong type. We define 
`ClassFormatException` for this very purpose. Examine the reset of the code 
base for examples.
   
   



##########
src/test/java/org/apache/bcel/data/readAttributeTest.java:
##########
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+ package org.apache.bcel.data;
+
+ import static org.junit.jupiter.api.Assertions.assertThrows;
+ import java.io.DataInputStream;
+ import java.io.ByteArrayInputStream;
+ import java.security.InvalidParameterException;
+ import org.apache.bcel.classfile.Attribute;
+ import org.apache.bcel.classfile.Constant;
+ import org.apache.bcel.classfile.ConstantPool;
+ import org.junit.jupiter.api.Test;
+ 
+ public class readAttributeTest {

Review Comment:
   Class name does not follow Java conventions.



##########
src/main/java/org/apache/bcel/classfile/Attribute.java:
##########
@@ -125,8 +132,8 @@ public static Attribute readAttribute(final DataInput 
dataInput, final ConstantP
             }
         }
 
-        // Call proper constructor, depending on 'tag'
-        switch (tag) {
+    // Call proper constructor, depending on 'tag'

Review Comment:
   The indentation is still messed up, no need to change it.
   



##########
src/main/java/org/apache/bcel/classfile/Attribute.java:
##########
@@ -113,10 +114,16 @@ public static Attribute readAttribute(final DataInput 
dataInput, final ConstantP
         // Get class name from constant pool via 'name_index' indirection
         final int nameIndex = dataInput.readUnsignedShort();
         final String name = constantPool.getConstantUtf8(nameIndex).getBytes();
-
+        // Validate name
+        if (name == null || name.isEmpty()) {

Review Comment:
   Reuse `StringUtils.isEmpty()`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to