Skip to content

Commit

Permalink
Merge pull request #19 from babsingh/jcl_tnpe_to_ncdfe
Browse files Browse the repository at this point in the history
Translate TypeNotPresentException to NoClassDefFoundError
  • Loading branch information
DanHeidinga authored Sep 25, 2017
2 parents 3551fdb + 70a939e commit a0c8d18
Showing 1 changed file with 31 additions and 2 deletions.
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

0 comments on commit a0c8d18

Please sign in to comment.