You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by sj...@apache.org on 2022/03/05 17:21:26 UTC
[maven-dependency-analyzer] branch master updated: [MSHARED-1037] CONSTANT_METHOD_TYPE should not add to classes (#53)
This is an automated email from the ASF dual-hosted git repository.
sjaranowski pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-dependency-analyzer.git
The following commit(s) were added to refs/heads/master by this push:
new 5e78233 [MSHARED-1037] CONSTANT_METHOD_TYPE should not add to classes (#53)
5e78233 is described below
commit 5e782336a8f1ca532df488dceaeacfa72248d6e7
Author: Chas Honton <ch...@proofpoint.com>
AuthorDate: Sat Mar 5 09:21:21 2022 -0800
[MSHARED-1037] CONSTANT_METHOD_TYPE should not add to classes (#53)
* CONSTANT_METHOD_TYPE should not add to classes
* unit tests
---
.../analyzer/asm/ConstantPoolParser.java | 11 ++++--
.../analyzer/asm/ResultCollectorTest.java | 12 +++++++
.../analyzer/testcases/MethodHandleCases.java | 41 ++++++++++++++++++++++
3 files changed, 62 insertions(+), 2 deletions(-)
diff --git a/src/main/java/org/apache/maven/shared/dependency/analyzer/asm/ConstantPoolParser.java b/src/main/java/org/apache/maven/shared/dependency/analyzer/asm/ConstantPoolParser.java
index 7bb2748..4937a97 100644
--- a/src/main/java/org/apache/maven/shared/dependency/analyzer/asm/ConstantPoolParser.java
+++ b/src/main/java/org/apache/maven/shared/dependency/analyzer/asm/ConstantPoolParser.java
@@ -124,11 +124,13 @@ public class ConstantPoolParser
throw new RuntimeException( "Unknown constant pool type '" + tag + "'" );
case CONSTANT_UTF8:
stringConstants.put( ix, decodeString( buf ) );
- continue;
+ break;
case CONSTANT_CLASS:
- case CONSTANT_METHOD_TYPE:
classes.add( (int) buf.getChar() );
break;
+ case CONSTANT_METHOD_TYPE:
+ consumeMethodType( buf );
+ break;
case CONSTANT_FIELDREF:
case CONSTANT_METHODREF:
case CONSTANT_INTERFACEMETHODREF:
@@ -219,6 +221,11 @@ public class ConstantPoolParser
return className.indexOf( '/' ) != -1;
}
+ private static void consumeMethodType( ByteBuffer buf )
+ {
+ buf.getChar();
+ }
+
private static void consumeReference( ByteBuffer buf )
{
buf.getChar();
diff --git a/src/test/java/org/apache/maven/shared/dependency/analyzer/asm/ResultCollectorTest.java b/src/test/java/org/apache/maven/shared/dependency/analyzer/asm/ResultCollectorTest.java
index f61201f..9ccb518 100644
--- a/src/test/java/org/apache/maven/shared/dependency/analyzer/asm/ResultCollectorTest.java
+++ b/src/test/java/org/apache/maven/shared/dependency/analyzer/asm/ResultCollectorTest.java
@@ -24,6 +24,7 @@ import java.io.InputStream;
import java.util.Set;
import org.apache.maven.shared.dependency.analyzer.testcases.ArrayCases;
+import org.apache.maven.shared.dependency.analyzer.testcases.MethodHandleCases;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.Test;
@@ -53,4 +54,15 @@ public class ResultCollectorTest
.contains( "java.lang.annotation.Annotation" )
.contains( "java.lang.reflect.Constructor" );
}
+
+ @Test
+ public void testNoMethodHandle()
+ throws IOException
+ {
+ Set<String> dependencies = getDependencies( MethodHandleCases.class );
+ for ( String dependency : dependencies )
+ {
+ assertThat( dependency ).doesNotStartWith( "(" );
+ }
+ }
}
\ No newline at end of file
diff --git a/src/test/java/org/apache/maven/shared/dependency/analyzer/testcases/MethodHandleCases.java b/src/test/java/org/apache/maven/shared/dependency/analyzer/testcases/MethodHandleCases.java
new file mode 100644
index 0000000..969dac8
--- /dev/null
+++ b/src/test/java/org/apache/maven/shared/dependency/analyzer/testcases/MethodHandleCases.java
@@ -0,0 +1,41 @@
+package org.apache.maven.shared.dependency.analyzer.testcases;
+
+/*
+ * 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.util.function.Consumer;
+
+public class MethodHandleCases
+{
+ public void sayHello()
+ {
+ sayHello( this::callSite );
+ }
+
+ void sayHello( Consumer<String> consumer )
+ {
+ consumer.accept( "hello" );
+ }
+
+ private void callSite( String output )
+ {
+ System.out.println( output );
+ }
+
+}