Use rethrow puzzler in the ClassValue

This commit is contained in:
Uwe Schindler 2016-06-15 18:36:45 +02:00
parent 6487940a79
commit 04ab42cdf5
2 changed files with 5 additions and 4 deletions

View File

@ -138,7 +138,7 @@ public final class Def {
/** Hack to rethrow unknown Exceptions from {@link MethodHandle#invokeExact}: */ /** Hack to rethrow unknown Exceptions from {@link MethodHandle#invokeExact}: */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private static <T extends Throwable> void rethrow(Throwable t) throws T { static <T extends Throwable> void rethrow(Throwable t) throws T {
throw (T) t; throw (T) t;
} }

View File

@ -158,11 +158,12 @@ public final class DefBootstrap {
final ClassValue<MethodHandle> megamorphicCache = new ClassValue<MethodHandle>() { final ClassValue<MethodHandle> megamorphicCache = new ClassValue<MethodHandle>() {
@Override @Override
protected MethodHandle computeValue(Class<?> receiverType) { protected MethodHandle computeValue(Class<?> receiverType) {
// it's too stupid that we cannot throw checked exceptions... (use rethrow puzzler):
try { try {
return lookup(flavor, name, receiverType, callArgs).asType(type); return lookup(flavor, name, receiverType, callArgs).asType(type);
} catch (Throwable e) { } catch (Throwable t) {
// XXX: fix that Def.rethrow(t);
throw new RuntimeException(e); throw new AssertionError();
} }
} }
}; };