我不确定您是否只是使用带有 Titan 的旧版本 Gremlin 服务器,但从 TinkerPop 3.2.3 开始,您在输出和服务器日志中会收到相当严重的错误:
$ curl "http://localhost:8182?gremlin=100/0"
{"message":"Division by zero","Exception-Class":"java.lang.ArithmeticException"}
$ curl "http://localhost:8182?gremlin=x=100\nx/0"
{"message":"startup failed:\nScript4.groovy: 1: unexpected char: '\\' @ line 1, column 6.\n x=100\\nx/0\n ^\n\n1 error\n","Exception-Class":"org.codehaus.groovy.control.MultipleCompilationErrorsException"}
请注意,服务器输出也非常详细:
[WARN] HttpGremlinEndpointHandler - Invalid request - responding with 500 Internal Server Error and startup failed:
Script4.groovy: 1: unexpected char: '\' @ line 1, column 6.
x=100\nx/0
^
1 error
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Script4.groovy: 1: unexpected char: '\' @ line 1, column 6.
x=100\nx/0
^
1 error
at org.codehaus.groovy.control.ErrorCollector.failIfErrors(ErrorCollector.java:310)
at org.codehaus.groovy.control.ErrorCollector.addFatalError(ErrorCollector.java:150)
at org.codehaus.groovy.control.ErrorCollector.addError(ErrorCollector.java:120)
at org.codehaus.groovy.control.ErrorCollector.addError(ErrorCollector.java:132)
at org.codehaus.groovy.control.SourceUnit.addError(SourceUnit.java:360)
at org.codehaus.groovy.antlr.AntlrParserPlugin.transformCSTIntoAST(AntlrParserPlugin.java:140)
at org.codehaus.groovy.antlr.AntlrParserPlugin.parseCST(AntlrParserPlugin.java:111)
at org.codehaus.groovy.control.SourceUnit.parse(SourceUnit.java:237)
at org.codehaus.groovy.control.CompilationUnit$1.call(CompilationUnit.java:167)
at org.codehaus.groovy.control.CompilationUnit.applyToSourceUnits(CompilationUnit.java:931)
at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:593)
at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:569)
at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:546)
at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:298)
at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:268)
at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:254)
at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:211)
at org.apache.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngine.getScriptClass(GremlinGroovyScriptEngine.java:527)
at org.apache.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngine.eval(GremlinGroovyScriptEngine.java:446)
at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:233)
at org.apache.tinkerpop.gremlin.groovy.engine.ScriptEngines.eval(ScriptEngines.java:119)
at org.apache.tinkerpop.gremlin.groovy.engine.GremlinExecutor.lambda$eval$2(GremlinExecutor.java:287)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
我怀疑这个问题可能是 Titan 1.0 附带的早期版本的 TinkerPop 中的一个问题,并且早就得到了改进。