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-1247] java.lang.RuntimeException: Unknown constant pool type #88

Merged
merged 1 commit into from
Apr 29, 2023
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 @@ -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!");
}
}