Skip to content

Commit

Permalink
[MSHARED-1247] java.lang.RuntimeException: Unknown constant pool type
Browse files Browse the repository at this point in the history
'17'

[MSHARED-1247] java.lang.RuntimeException: Unknown constant pool type
'17'
  • Loading branch information
garydgregory authored and slawekjaranowski committed Apr 29, 2023
1 parent a9a6fd3 commit a9be307
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,13 @@ private static void acceptDirectory(File directory, ClassFileVisitor visitor) th

for (Path path : classFiles) {
try (InputStream in = Files.newInputStream(path)) {
visitClass(directory, path, in, visitor);
try {
visitClass(directory, path, in, visitor);
} catch (RuntimeException e) {
// visitClass throws RuntimeException
throw new RuntimeException(
String.format("%s from directory = %s, path = %s", e.getMessage(), directory, path), e);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ public class ConstantPoolParser {
/** Constant <code>CONSTANT_METHOD_TYPE=16</code> */
public static final byte CONSTANT_METHOD_TYPE = 16;

/** Constant <code>CONSTANT_INVOKE=17</code> */
public static final byte CONSTANT_INVOKE = 17;

/** Constant <code>CONSTANT_INVOKE_DYNAMIC=18</code> */
public static final byte CONSTANT_INVOKE_DYNAMIC = 18;

Expand Down Expand Up @@ -156,6 +159,9 @@ static Set<String> parseConstantPoolClassReferences(ByteBuffer buf) {
case CONSTANT_METHODHANDLE:
consumeMethodHandle(buf);
break;
case CONSTANT_INVOKE:
consumeDynamic(buf);
break;
case CONSTANT_INVOKE_DYNAMIC:
consumeInvokeDynamic(buf);
break;
Expand Down Expand Up @@ -260,6 +266,11 @@ private static void consumeMethodHandle(ByteBuffer buf) {
buf.getChar();
}

private static void consumeDynamic(ByteBuffer buf) {
buf.getChar(); // u2 bootstrap_method_attr_index;
buf.getChar(); // u2 name_and_type_index;
}

private static void consumeInvokeDynamic(ByteBuffer buf) {
buf.getChar();
buf.getChar();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@

import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Set;

import org.apache.maven.shared.dependency.analyzer.testcases.ArrayCases;
Expand All @@ -40,6 +43,17 @@ Set<String> getDependencies(Class<?> inspectClass) throws IOException {
return visitor.getDependencies();
}

@Test
public void testJava11Invoke() throws IOException {
String className = "issue362.Bcel362";
Path path = Paths.get(
"src/test/resources/org/apache/maven/shared/dependency/analyzer/commons-bcel-issue362/Bcel362.class");
DependencyClassFileVisitor visitor = new DependencyClassFileVisitor();
try (InputStream is = Files.newInputStream(path)) {
visitor.visitClass(className, is);
}
}

@Test
public void testArrayCases() throws IOException {
Set<String> dependencies = getDependencies(ArrayCases.class);
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* 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.
*/

package issue362;

/**
* Compile to Java 11 byte code, then instrument with JaCoCo in order to add
* condy (constant dynamic) instructions
*/
public class Bcel362 {
public static void main(String[] args) {
System.out.println("Hello world!");
}
}

0 comments on commit a9be307

Please sign in to comment.