diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/Def.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/Def.java index 158086ab429..c24261dc5ac 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/Def.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/Def.java @@ -138,7 +138,7 @@ public final class Def { /** Hack to rethrow unknown Exceptions from {@link MethodHandle#invokeExact}: */ @SuppressWarnings("unchecked") - private static void rethrow(Throwable t) throws T { + static void rethrow(Throwable t) throws T { throw (T) t; } diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/DefBootstrap.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/DefBootstrap.java index 181aa10061f..f1651b5c869 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/DefBootstrap.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/DefBootstrap.java @@ -158,11 +158,12 @@ public final class DefBootstrap { final ClassValue megamorphicCache = new ClassValue() { @Override protected MethodHandle computeValue(Class receiverType) { + // it's too stupid that we cannot throw checked exceptions... (use rethrow puzzler): try { return lookup(flavor, name, receiverType, callArgs).asType(type); - } catch (Throwable e) { - // XXX: fix that - throw new RuntimeException(e); + } catch (Throwable t) { + Def.rethrow(t); + throw new AssertionError(); } } };