delight.nashornsandbox.exceptions.ScriptAbuseException Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of delight-nashorn-sandbox Show documentation
Show all versions of delight-nashorn-sandbox Show documentation
A safe sandbox to execute JavaScript code from Nashorn.
The newest version!
package delight.nashornsandbox.exceptions;
/**
* Exception is thrown when JS script abuse was detected.
*
* Created on 2017.11.24
*
* @author Marcin Golebski
* @version $Id$
*/
public class ScriptAbuseException extends RuntimeException {
private static final long serialVersionUID = 1L;
private final boolean scriptKilled;
public ScriptAbuseException(final String message, final boolean scriptKilled,
final Throwable throwable) {
super(message, throwable);
this.scriptKilled = scriptKilled;
}
/**
* Check if script when asked exited nicely, or not.
*
* Note, killint java thread is very dangerous to VM health.
*
*
* @return true
when evaluator thread was finished by
* {@link Thread#stop()} method, false
when only
* {@link Thread#interrupt()} was used
*/
public boolean isScriptKilled() {
return scriptKilled;
}
@Override
public String getMessage() {
if(scriptKilled) {
return super.getMessage() + " The operation could NOT be gracefully interrupted.";
}
else {
return super.getMessage();
}
}
}