You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by GitBox <gi...@apache.org> on 2022/02/23 06:56:04 UTC

[GitHub] [maven-dependency-analyzer] slawekjaranowski commented on a change in pull request #55: MSHARED-1039: Fix array parsing

slawekjaranowski commented on a change in pull request #55:
URL: https://github.com/apache/maven-dependency-analyzer/pull/55#discussion_r812599452



##########
File path: src/main/java/org/apache/maven/shared/dependency/analyzer/asm/ResultCollector.java
##########
@@ -57,15 +57,24 @@ public void addName( String name )
         }
 
         // decode arrays
-        if ( name.startsWith( "[L" ) && name.endsWith( ";" ) )
+        if ( name.charAt( 0 ) == '[' )
         {
-            name = name.substring( 2, name.length() - 1 );
+            int i = 0;
+            do
+            {
+                ++i;
+            }
+            while ( name.charAt( i ) == '[' ); // could have array of array ...

Review comment:
       can `name` contains multiple `[` ... ?
   we don't check length of name - can couse `IndexOutOfBoundsException`

##########
File path: src/test/java/org/apache/maven/shared/dependency/analyzer/asm/ResultCollectorTest.java
##########
@@ -0,0 +1,61 @@
+package org.apache.maven.shared.dependency.analyzer.asm;
+
+/*
+ * 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
+ *
+ *  http://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.
+ */
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Set;
+
+import junit.framework.TestCase;
+import org.apache.maven.shared.dependency.analyzer.testcases.ArrayCases;
+import static org.assertj.core.api.Assertions.assertThat;
+import org.junit.Test;
+
+public class ResultCollectorTest
+    extends TestCase

Review comment:
       extends not needed for junit4

##########
File path: src/test/java/org/apache/maven/shared/dependency/analyzer/asm/ResultCollectorTest.java
##########
@@ -0,0 +1,61 @@
+package org.apache.maven.shared.dependency.analyzer.asm;
+
+/*
+ * 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
+ *
+ *  http://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.
+ */
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Set;
+
+import junit.framework.TestCase;
+import org.apache.maven.shared.dependency.analyzer.testcases.ArrayCases;
+import static org.assertj.core.api.Assertions.assertThat;
+import org.junit.Test;
+
+public class ResultCollectorTest
+    extends TestCase
+{
+    Set<String> getDependencies( Class<?> inspectClass )
+        throws IOException
+    {
+        String className = inspectClass.getName();
+        String path = '/' + className.replace( '.', '/' ) + ".class";
+        DependencyClassFileVisitor visitor = new DependencyClassFileVisitor();
+        try ( InputStream is = inspectClass.getResourceAsStream( path ) )
+        {
+            visitor.visitClass( className, is );
+        }
+        return visitor.getDependencies();
+    }
+
+    @Test
+    public void testArrayCases()
+        throws IOException
+    {
+        Set<String> dependencies = getDependencies( ArrayCases.class );
+        assertThat( dependencies ).doesNotContain( "[I" );
+        for ( String dependency : dependencies )
+        {
+            assertThat( dependency ).doesNotStartWith( "[" );
+        }

Review comment:
       We can use:
   
   ```
   assertThat( dependencies ).allSatisfy( dependency -> assertThat( dependency ).doesNotStartWith( "[" ) );
   ```




-- 
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: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org