Skip to content

Commit e9cfd5f

Browse files
jdconradbreskeby
authored andcommitted
do not wrap error
1 parent 9751859 commit e9cfd5f

File tree

5 files changed

+8
-8
lines changed

5 files changed

+8
-8
lines changed

modules/lang-painless/src/main/java/org/elasticsearch/painless/DefBootstrap.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ protected MethodHandle computeValue(Class<?> receiverType) {
204204
// ClassValue.getFromHashMap wraps checked exceptions as Error, so we
205205
// use a sentinel class [PainlessWrapperError] here to work around
206206
// this issue and later unwrap the original exception
207-
Def.rethrow(new PainlessWrappedError(t));
207+
Def.rethrow(t instanceof Exception ? new PainlessWrappedException((Exception) t) : t);
208208
throw new AssertionError();
209209
}
210210
}

modules/lang-painless/src/main/java/org/elasticsearch/painless/PainlessScript.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public interface PainlessScript {
4646
* @return The generated ScriptException.
4747
*/
4848
default ScriptException convertToScriptException(Throwable t, Map<String, List<String>> extraMetadata) {
49-
if (t instanceof PainlessWrappedError) {
49+
if (t instanceof PainlessWrappedException) {
5050
t = t.getCause();
5151
}
5252
// create a script stack: this is just the script portion

modules/lang-painless/src/main/java/org/elasticsearch/painless/PainlessWrappedError.java renamed to modules/lang-painless/src/main/java/org/elasticsearch/painless/PainlessWrappedException.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@
1414
* which leads to unexpected behavior in Painless. This class is used as a
1515
* workaround for that exception wrapping.
1616
*/
17-
public class PainlessWrappedError extends Error {
17+
public class PainlessWrappedException extends Error {
1818

1919
/**
2020
* Constructor.
21-
* @param cause The {@link Throwable} cause.
21+
* @param cause The {@link Exception} cause.
2222
*/
23-
public PainlessWrappedError(final Throwable cause) {
23+
public PainlessWrappedException(final Exception cause) {
2424
super(cause);
2525
}
2626
}

modules/lang-painless/src/main/java/org/elasticsearch/painless/phase/PainlessUserTreeToIRTreePhase.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import org.elasticsearch.painless.Location;
1313
import org.elasticsearch.painless.PainlessError;
1414
import org.elasticsearch.painless.PainlessExplainError;
15-
import org.elasticsearch.painless.PainlessWrappedError;
15+
import org.elasticsearch.painless.PainlessWrappedException;
1616
import org.elasticsearch.painless.ScriptClassInfo;
1717
import org.elasticsearch.painless.ScriptClassInfo.MethodArgument;
1818
import org.elasticsearch.painless.ir.BinaryImplNode;
@@ -416,7 +416,7 @@ protected static void injectSandboxExceptions(FunctionNode irFunctionNode) {
416416

417417
for (Class<? extends Throwable> throwable : List.of(
418418
PainlessError.class,
419-
PainlessWrappedError.class,
419+
PainlessWrappedException.class,
420420
LinkageError.class,
421421
OutOfMemoryError.class,
422422
StackOverflowError.class,

modules/lang-painless/src/test/java/org/elasticsearch/painless/DefBootstrapTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ public void testMegamorphic() throws Throwable {
139139
map.put("a", "b");
140140
assertEquals(2, (int) handle.invokeExact((Object) map));
141141

142-
final PainlessWrappedError pwe = expectThrows(PainlessWrappedError.class, () -> {
142+
final PainlessWrappedException pwe = expectThrows(PainlessWrappedException.class, () -> {
143143
Integer.toString((int) handle.invokeExact(new Object()));
144144
});
145145
assertTrue(pwe.getCause() instanceof IllegalArgumentException);

0 commit comments

Comments
 (0)