Skip to content

Commit 29c0b6c

Browse files
committed
avoid static dependencies to Polyglot classes
1 parent 06841ed commit 29c0b6c

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

src/main/java/org/openstreetmap/josm/plugins/scripting/ui/console/ErrorOutputPanel.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package org.openstreetmap.josm.plugins.scripting.ui.console;
22

33

4-
import org.graalvm.polyglot.PolyglotException;
54
import org.mozilla.javascript.EcmaError;
65
import org.openstreetmap.josm.plugins.scripting.graalvm.GraalVMFacadeFactory;
76

@@ -39,7 +38,7 @@ protected void build() {
3938
add(editorScrollPane, BorderLayout.CENTER);
4039
}
4140

42-
protected void displayPolyglotException(PolyglotException exception) {
41+
protected void displayPolyglotException(Throwable exception) {
4342
paneOutput.setText(formatPolyglotException(exception));
4443
paneOutput.setCaretPosition(0);
4544
}
@@ -78,9 +77,16 @@ public void displayException(@Null Throwable exception) {
7877
return;
7978
}
8079
if (GraalVMFacadeFactory.isGraalVMPresent()) {
81-
final var polyglotException = lookupCauseByExceptionType(exception, PolyglotException.class);
82-
if (polyglotException != null) {
83-
displayPolyglotException((PolyglotException) polyglotException);
80+
try {
81+
// dynamic lookup necessary
82+
final var clazz = Class.forName("org.graalvm.polyglot.PolyglotException");
83+
final var polyglotException = lookupCauseByExceptionType(exception, clazz);
84+
if (polyglotException != null) {
85+
displayPolyglotException(polyglotException);
86+
return;
87+
}
88+
89+
} catch(ClassNotFoundException e) {
8490
return;
8591
}
8692
}
@@ -97,7 +103,7 @@ public void displayException(@Null Throwable exception) {
97103
displayGeneralException(exception);
98104
}
99105

100-
protected @Null Throwable lookupCauseByExceptionType(Throwable t, Class<? extends Throwable> clazz) {
106+
protected @Null Throwable lookupCauseByExceptionType(Throwable t, Class<?> clazz) {
101107
while(t != null) {
102108
if (clazz.isInstance(t)) {
103109
break;
@@ -107,7 +113,7 @@ public void displayException(@Null Throwable exception) {
107113
return t;
108114
}
109115

110-
protected String formatPolyglotException(@NotNull final PolyglotException exception) {
116+
protected String formatPolyglotException(@NotNull final Throwable exception) {
111117
return exception.getMessage() +
112118
"\n" +
113119
Arrays.stream(exception.getStackTrace())

0 commit comments

Comments
 (0)