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

Translate TypeNotPresentException to NoClassDefFoundError #19

Merged
merged 1 commit into from
Sep 25, 2017
Merged
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
33 changes: 31 additions & 2 deletions jcl/src/java.base/share/classes/java/lang/invoke/MethodHandle.java
Original file line number Diff line number Diff line change
Expand Up @@ -823,7 +823,11 @@ private static final MethodHandle resolveInvokeDynamic(Class<?> clazz, String na
MethodType type = null;

try {
type = MethodType.fromMethodDescriptorString(methodDescriptor, VM.getVMLangAccess().getClassloader(clazz));
try {
type = MethodType.fromMethodDescriptorString(methodDescriptor, VM.getVMLangAccess().getClassloader(clazz));
} catch (TypeNotPresentException e) {
throw throwNoClassDefFoundError(e);
}
int bsmIndex = unsafe.getShort(bsmData);
int bsmArgCount = unsafe.getShort(bsmData + BSM_ARGUMENT_COUNT_OFFSET);
long bsmArgs = bsmData + BSM_ARGUMENTS_OFFSET;
Expand Down Expand Up @@ -892,7 +896,11 @@ private static final MethodHandle resolveInvokeDynamic(Class<?> clazz, String na
cpEntry = cp.getDoubleAt(index);
break;
case 13:
cpEntry = getCPMethodTypeAt(clazz, index);
try {
cpEntry = getCPMethodTypeAt(clazz, index);
} catch (TypeNotPresentException e) {
throw throwNoClassDefFoundError(e);
}
break;
case 14:
cpEntry = getCPMethodHandleAt(clazz, index);
Expand Down Expand Up @@ -963,6 +971,27 @@ private static final MethodHandle resolveInvokeDynamic(Class<?> clazz, String na
return result;
}

/**
* Helper method to throw NoClassDefFoundError if the cause of TypeNotPresentException
* is ClassNotFoundException. Otherwise, re-throw TypeNotPresentException.
*
* @param an instance of TypeNotPresentException
*
* @return Throwable to prevent any fall through case
*
* @throws NoClassDefFoundError if the cause of TypeNotPresentException is
* ClassNotFoundException. Otherwise, re-throw TypeNotPresentException.
*/
private static Throwable throwNoClassDefFoundError(TypeNotPresentException e) {
Throwable cause = e.getCause();
if (cause instanceof ClassNotFoundException) {
NoClassDefFoundError noClassDefFoundError = new NoClassDefFoundError(cause.getMessage());
noClassDefFoundError.initCause(cause);
throw noClassDefFoundError;
}
throw e;
}

@Override
public String toString() {
return "MethodHandle" + type.toString(); //$NON-NLS-1$
Expand Down