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/22 05:17:58 UTC

[GitHub] [maven-dependency-analyzer] chonton opened a new pull request #55: MSHARED-1039: Fix array parsing

chonton opened a new pull request #55:
URL: https://github.com/apache/maven-dependency-analyzer/pull/55


   Arrays [of Arrays]+ of class types should add just the class type to dependency set
   
   Arrays of scalar types should not be added
   
   
    - [ x] I hereby declare this contribution to be licenced under the [Apache License Version 2.0, January 2004](http://www.apache.org/licenses/LICENSE-2.0)
   
    - [ x] In any other case, please file an [Apache Individual Contributor License Agreement](https://www.apache.org/licenses/icla.pdf).
   
   


-- 
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



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

Posted by GitBox <gi...@apache.org>.
slawekjaranowski commented on pull request #55:
URL: https://github.com/apache/maven-dependency-analyzer/pull/55#issuecomment-1047484220


   Thanks. Will be good to add some of test. Unit or IT, of course we can extends existing one.


-- 
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



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

Posted by GitBox <gi...@apache.org>.
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



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

Posted by GitBox <gi...@apache.org>.
chonton commented on a change in pull request #55:
URL: https://github.com/apache/maven-dependency-analyzer/pull/55#discussion_r819896171



##########
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:
       @slawekjaranowski - any thoughts?




-- 
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



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

Posted by GitBox <gi...@apache.org>.
chonton commented on a change in pull request #55:
URL: https://github.com/apache/maven-dependency-analyzer/pull/55#discussion_r813359903



##########
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:
       name can contain any number of '[' - see [Field Descriptors](https://docs.oracle.com/javase/specs/jvms/se17/html/jvms-4.html#jvms-4.3.2) in jvm spec.
   Yes, we could have IndexOutOfBoundsException if class is malformed.  Does it matter what sort of exception is thrown?  




-- 
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



[GitHub] [maven-dependency-analyzer] slawekjaranowski merged pull request #55: MSHARED-1039: Fix array parsing

Posted by GitBox <gi...@apache.org>.
slawekjaranowski merged pull request #55:
URL: https://github.com/apache/maven-dependency-analyzer/pull/55


   


-- 
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



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

Posted by GitBox <gi...@apache.org>.
chonton commented on a change in pull request #55:
URL: https://github.com/apache/maven-dependency-analyzer/pull/55#discussion_r819895664



##########
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:
       done

##########
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:
       done




-- 
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