Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MSHARED-1037: CONSTANT_METHOD_TYPE should not add to classes #53

Merged
merged 2 commits into from
Mar 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,13 @@ static Set<String> parseConstantPoolClassReferences( ByteBuffer buf )
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:
Expand Down Expand Up @@ -219,6 +221,11 @@ private static boolean isImportableClass( String className )
return className.indexOf( '/' ) != -1;
}

private static void consumeMethodType( ByteBuffer buf )
{
buf.getChar();
}

private static void consumeReference( ByteBuffer buf )
{
buf.getChar();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
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;

Expand Down Expand Up @@ -53,4 +54,15 @@ public void testArrayCases()
.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( "(" );
}
}
}
Original file line number Diff line number Diff line change
@@ -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 );
}

}