Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve graalvm multi thread errors with reason #453

Merged
merged 1 commit into from
Mar 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions src/main/java/com/rapiddweller/benerator/script/GraalScript.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,20 @@ public GraalScript(String text, Engine scriptEngine, String languageId) {
}

@Override
public Object evaluate(Context context) throws ScriptException {
Value returnValue = globalPolyglotCtx.evalScript(context, text, language);
GraalValueConverter converter = new GraalValueConverter();
return converter.convert(returnValue);
public synchronized Object evaluate(Context context) throws ScriptException {
try {
Value returnValue = globalPolyglotCtx.evalScript(context, text, language);
GraalValueConverter converter = new GraalValueConverter();
return converter.convert(returnValue);
} catch (IllegalStateException e) {
if(e.getMessage().contains("Multi threaded access requested")) {
throw new ScriptException(String.format("Multi thread access requested. GraalVM Context is not thread safe. " +
"Please check your script and make sure there is no multi thread access with '%s'", text), null);
}
else {
throw new ScriptException("Error evaluating script: " + text, e);
}
}
}

@Override
Expand Down
Loading