我们正在从Java 7切换到Java 8(大概我认为:-)),我们遇到了使用HibernateValidator的ScriptAssert的问题。看起来Nashorn Javascript引擎未正确初始化
ScriptAssert使用如下
@ScriptAssert(
lang = "javascript",
script = "_this.owner != null && _this.owner.id != null"
+ " && _this.owner.id.matches('^[0-9A-F]{8}-[0-9A-F]{4}-[1-5][0-9A-
F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$')"
)
我们得到的是如下所示的异常,这发生在Linux上的JDK1.8.0_131上。
任何帮助将不胜感激。以下是堆栈跟踪。
java.lang.NoSuchMethodError: java.lang.invoke.MethodHandle.invokeExact(Ljava /郎/对象; Ljava /郎/对象;)V 在jdk.nashorn.internal.runtime.AccessorProperty.invokeSetter(AccessorProperty.java:462) 〜[nashorn.jar:?] 在jdk.nashorn.internal.runtime.AccessorProperty.setValue(AccessorProperty.java:485) 〜[nashorn.jar:?] 在jdk.nashorn.internal.runtime.ScriptObject.erasePropertyValue(ScriptObject.java:916) 〜[nashorn.jar:?] 在jdk.nashorn.internal.runtime.ScriptObject.deleteOwnProperty(ScriptObject.java:928) 〜[nashorn.jar:?] 在jdk.nashorn.internal.runtime.ScriptFunction.createBuiltin(ScriptFunction.java:324) 〜[nashorn.jar:?] 在jdk.nashorn.internal.runtime.ScriptFunction.createBuiltin(ScriptFunction.java:339) 〜[nashorn.jar:?] 在jdk.nashorn.internal.runtime.ScriptFunction.createBuiltin(ScriptFunction.java:350) 〜[nashorn.jar:?] 在jdk.nashorn.internal.objects.NativeFunction $ Prototype。(未知 来源)〜[nashorn.jar:?] 在jdk.nashorn.internal.objects.NativeFunction $ Constructor。(未知 来源)〜[nashorn.jar:?] at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) 〜[:?1.8.0_131] at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) 〜[:?1.8.0_131] at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) 〜[:?1.8.0_131] at java.lang.reflect.Constructor.newInstance(Constructor.java:423) 〜[:?1.8.0_131] 在java.lang.Class.newInstance(Class.java:442)〜[?:1.8.0_131] 在jdk.nashorn.internal.objects.Global.initConstructor(Global.java:2549) 〜[nashorn.jar:?] 在jdk.nashorn.internal.objects.Global.initFunctionAndObject(Global.java:2618) 〜[nashorn.jar:?] 在jdk.nashorn.internal.objects.Global.init(Global.java:2257)〜[nashorn.jar:?] 在jdk.nashorn.internal.objects.Global.initBuiltinObjects(Global.java:1094) 〜[nashorn.jar:?] 在jdk.nashorn.internal.runtime.Context.initGlobal(Context.java:1150) 〜[nashorn.jar:?] 在jdk.nashorn.api.scripting.NashornScriptEngine.createNashornGlobal(NashornScriptEngine.java:360) 〜[nashorn.jar:?] 在jdk.nashorn.api.scripting.NashornScriptEngine。(NashornScriptEngine.java:143) 〜[nashorn.jar:?] 在jdk.nashorn.api.scripting.NashornScriptEngineFactory.getScriptEngine(NashornScriptEngineFactory.java:148) 〜[nashorn.jar:?] 在javax.script.ScriptEngineManager.getEngineByName(ScriptEngineManager.java:238) 〜[:?1.8.0_131] at org.hibernate.validator.internal.util.scriptengine.ScriptEvaluatorFactory.createNewScriptEvaluator(ScriptEvaluatorFactory.java:87) 〜[休眠验证器-5.4.1.Final.jar:5.4.1.Final] at org.hibernate.validator.internal.util.scriptengine.ScriptEvaluatorFactory.getScriptEvaluatorByLanguageName(ScriptEvaluatorFactory.java:70) 〜[休眠验证器-5.4.1.Final.jar:5.4.1.Final] at org.hibernate.validator.internal.constraintvalidators.hv.ScriptAssertContext.getScriptEvaluator(ScriptAssertContext.java:60) 〜[休眠验证器-5.4.1.Final.jar:5.4.1.Final] 在org.hibernate.validator.internal.constraintvalidators.hv.ScriptAssertContext。(ScriptAssertContext.java:34) 〜[休眠验证器-5.4.1.Final.jar:5.4.1.Final] at org.hibernate.validator.internal.constraintvalidators.hv.ScriptAssertValidator.initialize(ScriptAssertValidator.java:43) 〜[休眠验证器-5.4.1.Final.jar:5.4.1.Final] at org.hibernate.validator.internal.constraintvalidators.hv.ScriptAssertValidator.initialize(ScriptAssertValidator.java:28) 〜[休眠验证器-5.4.1.Final.jar:5.4.1.Final] at org.hibernate.validator.internal.engine.constraintvalidation.ConstraintValidatorManager.initializeValidator(ConstraintValidatorManager.java:225) 〜[休眠验证器-5.4.1.Final.jar:5.4.1.Final] at org.hibernate.validator.internal.engine.constraintvalidation.ConstraintValidatorManager.createAndInitializeValidator(ConstraintValidatorManager.java:151) 〜[休眠验证器-5.4.1.Final.jar:5.4.1.Final] 在org.hibernate.validator.internal.engine.constraintvalidation.ConstraintValidatorManager.getInitializedValidator(ConstraintValidatorManager.java:109) 〜[休眠验证器-5.4.1.Final.jar:5.4.1.Final] at org.hibernate.validator.internal.engine.constraintvalidation.ConstraintTree.getConstraintValidatorNoUnwrapping(ConstraintTree.java:301) 〜[休眠验证器-5.4.1.Final.jar:5.4.1.Final] at org.hibernate.validator.internal.engine.constraintvalidation.ConstraintTree.getConstraintValidatorInstanceForAutomaticUnwrapping(ConstraintTree.java:242) 〜[休眠验证器-5.4.1.Final.jar:5.4.1.Final] at org.hibernate.validator.internal.engine.constraintvalidation.ConstraintTree.getInitializedConstraintValidator(ConstraintTree.java:163) 〜[休眠验证器-5.4.1.Final.jar:5.4.1.Final] at org.hibernate.validator.internal.engine.constraintvalidation.ConstraintTree.validateConstraints(ConstraintTree.java:116) 〜[休眠验证器-5.4.1.Final.jar:5.4.1.Final] at org.hibernate.validator.internal.engine.constraintvalidation.ConstraintTree.validateConstraints(ConstraintTree.java:87) 〜[休眠验证器-5.4.1.Final.jar:5.4.1.Final] 在org.hibernate.validator.internal.metadata.core.MetaConstraint.validateConstraint(MetaConstraint.java:73) 〜[休眠验证器-5.4.1.Final.jar:5.4.1.Final] 在org.hibernate.validator.internal.engine.ValidatorImpl.validateMetaConstraint(ValidatorImpl.java:616) 〜[休眠验证器-5.4.1.Final.jar:5.4.1.Final] at org.hibernate.validator.internal.engine.ValidatorImpl.validateConstraint(ValidatorImpl.java:581) 〜[休眠验证器-5.4.1.Final.jar:5.4.1.Final] at org.hibernate.validator.internal.engine.ValidatorImpl.validateConstraintsForNonDefaultGroup(ValidatorImpl.java:543) 〜[休眠验证器-5.4.1.Final.jar:5.4.1.Final] at org.hibernate.validator.internal.engine.ValidatorImpl.validateConstraintsForCurrentGroup(ValidatorImpl.java:457) 〜[休眠验证器-5.4.1.Final.jar:5.4.1.Final] 在org.hibernate.validator.internal.engine.ValidatorImpl.validateInContext(ValidatorImpl.java:410) 〜[休眠验证器-5.4.1.Final.jar:5.4.1.Final] 在org.hibernate.validator.internal.engine.ValidatorImpl.validate(ValidatorImpl.java:207) 〜[休眠验证器-5.4.1.Final.jar:5.4.1.Final] 在org.springframework.validation.beanvalidation.SpringValidatorAdapter.validate(SpringValidatorAdapter.java:108) 〜[弹簧上下文4.1.6.RELEASE.jar:4.1.6.RELEASE] 在org.springframework.validation.DataBinder.validate(DataBinder.java:781) 〜[弹簧上下文4.1.6.RELEASE.jar:4.1.6.RELEASE]