apache/dubbo · error · IllegalStateException
unsupported route engine type: {type}
Error message
unsupported route engine type: {type} What it means
Thrown by ScriptStateRouter.getEngine() when ScriptEngineManager.getEngineByName(type) returns null — no JSR-223 script engine is registered under the configured name. The 'type' parameter defaults to a standard type (DEFAULT_SCRIPT_TYPE_KEY) but if the named engine is not on the classpath the router cannot function.
Source
Thrown at dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/script/ScriptStateRouter.java:129
*/
private String getRule(URL url) {
String vRule = url.getParameterAndDecoded(RULE_KEY);
if (StringUtils.isEmpty(vRule)) {
throw new IllegalStateException("route rule can not be empty.");
}
return vRule;
}
/**
* create ScriptEngine instance by type from url parameters, then cache it
*/
private ScriptEngine getEngine(URL url) {
String type = url.getParameter(TYPE_KEY, DEFAULT_SCRIPT_TYPE_KEY);
return ConcurrentHashMapUtils.computeIfAbsent(ENGINES, type, t -> {
ScriptEngine scriptEngine = new ScriptEngineManager().getEngineByName(type);
if (scriptEngine == null) {
throw new IllegalStateException("unsupported route engine type: " + type);
}
return scriptEngine;
});
}
@Override
protected BitList<Invoker<T>> doRoute(
BitList<Invoker<T>> invokers,
URL url,
Invocation invocation,
boolean needToPrintMessage,
Holder<RouterSnapshotNode<T>> nodeHolder,
Holder<String> messageHolder)
throws RpcException {
if (engine == null || function == null) {
if (needToPrintMessage) {
messageHolder.set("Directly Return. Reason: engine or function is null");
}View on GitHub (pinned to 3a3043227f)
Solutions
- Add a JSR-223 engine implementation to the classpath: for JavaScript on Java 15+ add the standalone Nashorn (org.openjdk.nashorn:nashorn-core) or GraalJS (org.graalvm.js:js-scriptengine + js); for Groovy add groovy-jsr223.
- Use an engine name that the registered engine actually publishes (try 'nashorn', 'js', 'graal.js', or 'groovy' depending on the jar).
- If no engine is desired, switch the router to a different type (condition/script-free) or remove it.
Example fix
# before (broken, Java 15+): nashorn removed -> getEngineByName returns null script://0.0.0.0/...?type=javascript&rule=... # after: add graaljs to pom and use its engine name # pom: org.graalvm.js:js-scriptengine, org.graalvm.js:js, org.graalvm.regex script://0.0.0.0/...?type=graal.js&rule=... # (or add org.openjdk.nashorn:nashorn-core and keep type=javascript)
Defensive patterns
Strategy: validation
Validate before calling
// Validate the script engine is available before constructing the router
String type = url.getParameter(TYPE_KEY, DEFAULT_SCRIPT_TYPE_KEY);
ScriptEngine engine = new ScriptEngineManager().getEngineByName(type);
if (engine == null) {
throw new IllegalArgumentException(
"No JSR-223 script engine named '" + type + "' on classpath. "
+ "Add nashorn-core (Java 15+) or graaljs/groovy-jsr223.");
}
return new ScriptStateRouter<>(url); Type guard
// Guard: an engine for the requested type exists
static boolean engineAvailable(String type) {
return new ScriptEngineManager().getEngineByName(type) != null;
} Try / catch
try {
new ScriptStateRouter<>(url);
} catch (IllegalStateException e) {
if (e.getMessage().contains("unsupported route engine type")) {
// engine jar missing; log and fall back to a non-script router
log.error("Script router engine missing: " + e.getMessage()
+ " Add org.openjdk.nashorn:nashorn-core or graaljs.");
} else throw e;
} Prevention
- On Java 15+, add a JSR-223 engine jar (nashorn-core or GraalJS) to use javascript routing.
- Use an engine name that the registered engine actually publishes.
- Smoke-test getEngineByName(type) in your environment before deploying script routing.
When it happens
Trigger: Configuring a script router with type=<name> for which no javax.script engine is available. Most common: using type=javascript on Java 15+, where Nashorn was removed and getEngineByName('javascript'/'js') returns null.
Common situations: Running on Java 15+ (Nashorn removed) and using javascript script routing; specifying an engine name that does not match any registered engine (e.g., 'groovy' without the groovy-jsr223 dependency); missing the JSR-223 implementation jar on the classpath.
Related errors
- route rule can not be empty.
- INTERNAL_ERROR
- Illegal affinity rule!
- Illegal route rule!
- Illegal route rule!
AI-assisted analysis of apache/dubbo@3a3043227f (2026-08-14).
Data as JSON: /api/errors/7ce82a200637e93b.
Report an issue: GitHub.