Changes in Java 9

Hannes Wallnöfer hannes.wallnoefer at oracle.com
Fri Dec 15 12:40:04 UTC 2017


Hi Nils,

Thanks for the code. Unfortunately you hit a bug in optimistic types, which is enabled by default in JDK 9. I’ve filed an issue for it and have a fix for it.

https://bugs.openjdk.java.net/browse/JDK-8193508

The good news is that it is quite easy to work around this bug by disabling optimistic types. The way to do this is to use the NashornScriptEngineFactory class to create the script engine:

import jdk.nashorn.api.scripting.NashornScriptEngineFactory; 

...
        ScriptEngine engine = new NashornScriptEngineFactory().getScriptEngine("-ot=false"); 

Hannes


> Am 06.12.2017 um 22:30 schrieb Nils Kilden-Pedersen <nilskp at gmail.com>:
> 
> Hannes,
> 
> I've sent an email with zip file attachment. 
> 
> Just letting you know in a separate email, in case it ends up being blocked.
> 
> Nils
> 
> On Wed, Dec 6, 2017 at 2:19 PM, Hannes Wallnöfer <hannes.wallnoefer at oracle.com> wrote:
> That would be https://bugs.openjdk.java.net/ but you need an OpenJDK account to file a bug.
> 
> Alternatively, if you can send me something reproduce the bug (could be a small snippet of code) I can file it for you.
> 
> Hannes
> 
> 
> > Am 06.12.2017 um 16:15 schrieb Nils Kilden-Pedersen <nilskp at gmail.com>:
> >
> > What's the right place to file a bug?
> >
> > On Mon, Dec 4, 2017 at 9:56 AM, Nils Kilden-Pedersen <nilskp at gmail.com>
> > wrote:
> >
> >> Thanks for bringing this up. It made me realize that my post was
> >> incomplete.
> >>
> >> These are the steps I take:
> >>
> >>   1. Initial step: Call engine.compile with the CS compiler source +
> >>   CoffeeScript.compile(coffeeCode, {runtime: 'none'}); which returns
> >>   CompiledScript that is retained and re-used. This works fine, also on
> >>   JDK 9.0.1.
> >>   2. For subsequent Coffeescript -> Javascript transpilation, I then
> >>   call engine.createBindings()
> >>   3. Then bindings.put("coffeeCode", csCode) to associate the CS code
> >>   with the JS variable coffeeCode mentioned in initial step
> >>   4. Call CompiledScript.eval(bindings). This is the step that fails in
> >>   9.0.1.
> >>
> >> I’m open to better ways to achieve this, if it’s inefficient or plain
> >> wrong.
> >> ​
> >>
> >> On Mon, Dec 4, 2017 at 8:47 AM, Hannes Wallnöfer <
> >> hannes.wallnoefer at oracle.com> wrote:
> >>
> >>> Hi Nils,
> >>>
> >>> Are you just evaluating the script files you linked in your first
> >>> message, or trying to do some further processing?
> >>>
> >>> Using the jjs tool from JDK 9.0.1 I see no errors running both versions
> >>> of CoffeeScript.
> >>>
> >>> Hannes
> >>>
> >>>> Am 03.12.2017 um 21:08 schrieb Nils Kilden-Pedersen <nilskp at gmail.com>:
> >>>>
> >>>> Ok, the minified vs non-minified may not be identical. I cannot find the
> >>>> default parameters in the minified version, so perhaps those are
> >>> removed.
> >>>>
> >>>> What does remain however, is that I can compile minified cs2
> >>>> <http://coffeescript.org/v2/browser-compiler/coffeescript.js> on JDK
> >>> 8_144,
> >>>> but not on 9.0.1.
> >>>>
> >>>>
> >>>> On Sun, Dec 3, 2017 at 1:39 PM, Nils Kilden-Pedersen <nilskp at gmail.com>
> >>>> wrote:
> >>>>
> >>>>> Further testing with the un-minified code (cs2
> >>>>> <https://unpkg.com/coffeescript@2.0.3/lib/coffeescript/browser.js>,
> >>> cs1
> >>>>> <https://unpkg.com/coffeescript@1.12.7/lib/coffee-script/browser.js>)
> >>>>> reveals the true problems in JDK 9.0.1
> >>>>>
> >>>>> In cs2, it’s ES6 syntax (default args), which (unexpectedly for me at
> >>>>> least), works in JDK 8:
> >>>>>
> >>>>>   <eval>:46:45 Expected , but found =
> >>>>> CoffeeScript.eval = function(code, options = {}) {
> >>>>>                                            ^ in <eval> at line number
> >>> 46 at column number 45
> >>>>>
> >>>>> And in cs1 it’s require that’s unresolved (also works in JDK 8):
> >>>>>
> >>>>> ReferenceError: "require" is not defined in <eval> at line number 7
> >>>>>
> >>>>> ​
> >>>>>
> >>>>> On Sun, Dec 3, 2017 at 11:02 AM, Nils Kilden-Pedersen <
> >>> nilskp at gmail.com>
> >>>>> wrote:
> >>>>>
> >>>>>> I just switched to the Java 9.0.1 runtime, and Nashorn now fails to
> >>> parse
> >>>>>> the Coffeescript compiler, which worked fine in Java 8_144.
> >>>>>>
> >>>>>> Coffeescript 2 compiler: http://coffeescript.org/v2/bro
> >>>>>> wser-compiler/coffeescript.js
> >>>>>>
> >>>>>> v1 also fails: http://coffeescript.org/v1/bro
> >>>>>> wser-compiler/coffee-script.js
> >>>>>>
> >>>>>> Exception is:
> >>>>>>
> >>>>>> javax.script.ScriptException: SyntaxError: unexpected  in <eval> at
> >>> line number 39 at column number 249736
> >>>>>> at jdk.scripting.nashorn/jdk.nashorn.api.scripting.NashornScrip
> >>> tEngine.throwAsScriptException(NashornScriptEngine.java:469)
> >>>>>> at jdk.scripting.nashorn/jdk.nashorn.api.scripting.NashornScrip
> >>> tEngine.evalImpl(NashornScriptEngine.java:425)
> >>>>>> at jdk.scripting.nashorn/jdk.nashorn.api.scripting.NashornScrip
> >>> tEngine.access$300(NashornScriptEngine.java:72)
> >>>>>> at jdk.scripting.nashorn/jdk.nashorn.api.scripting.NashornScrip
> >>> tEngine$3.eval(NashornScriptEngine.java:513)
> >>>>>> at java.scripting/javax.script.CompiledScript.eval(CompiledScri
> >>> pt.java:92)
> >>>>>> at scuff.js.CoffeeScriptCompiler.compile(CoffeeScriptCompiler.s
> >>> cala:115)
> >>>>>> at scuff.js.TestCoffeeScriptCompiler.cs2(TestCoffeeScriptCompil
> >>> er.scala:114)
> >>>>>> at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native
> >>> Method)
> >>>>>> at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invo
> >>> ke(NativeMethodAccessorImpl.java:62)
> >>>>>> at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.
> >>> invoke(DelegatingMethodAccessorImpl.java:43)
> >>>>>> at java.base/java.lang.reflect.Method.invoke(Method.java:564)
> >>>>>> at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(
> >>> FrameworkMethod.java:50)
> >>>>>> at org.junit.internal.runners.model.ReflectiveCallable.run(Refl
> >>> ectiveCallable.java:12)
> >>>>>> at org.junit.runners.model.FrameworkMethod.invokeExplosively(Fr
> >>> ameworkMethod.java:47)
> >>>>>> at org.junit.internal.runners.statements.InvokeMethod.evaluate(
> >>> InvokeMethod.java:17)
> >>>>>> at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
> >>>>>> at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit
> >>> 4ClassRunner.java:78)
> >>>>>> at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit
> >>> 4ClassRunner.java:57)
> >>>>>> at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
> >>>>>> at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
> >>>>>> at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
> >>>>>> at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
> >>>>>> at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
> >>>>>> at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
> >>>>>> at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.
> >>> run(JUnit4TestReference.java:86)
> >>>>>> at org.eclipse.jdt.internal.junit.runner.TestExecution.run(
> >>> TestExecution.java:38)
> >>>>>> at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTe
> >>> sts(RemoteTestRunner.java:539)
> >>>>>> at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTe
> >>> sts(RemoteTestRunner.java:761)
> >>>>>> at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(
> >>> RemoteTestRunner.java:461)
> >>>>>> at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(
> >>> RemoteTestRunner.java:207)
> >>>>>> Caused by: <eval>:39:249736 SyntaxError: unexpected
> >>>>>> at jdk.scripting.nashorn/jdk.nashorn.internal.objects.NativeErr
> >>> or.initException(NativeError.java:135)
> >>>>>> at jdk.scripting.nashorn/jdk.nashorn.internal.objects.NativeSyn
> >>> taxError.<init>(NativeSyntaxError.java:73)
> >>>>>> at jdk.scripting.nashorn/jdk.nashorn.internal.objects.NativeSyn
> >>> taxError.<init>(NativeSyntaxError.java:77)
> >>>>>> at jdk.scripting.nashorn/jdk.nashorn.internal.objects.NativeSyn
> >>> taxError.constructor(NativeSyntaxError.java:98)
> >>>>>> at jdk.scripting.nashorn.scripts/jdk.nashorn.internal.scripts.S
> >>> cript$Recompilation$2368$6956AA$\^eval\_.L:39-1#a#L:39-1#L:
> >>> 39#throwSyntaxError(<eval>:39)
> >>>>>> at jdk.scripting.nashorn.scripts/jdk.nashorn.internal.scripts.S
> >>> cript$Recompilation$2364$253073AA$\^eval\_$cu1$restOf.L:39-
> >>> 1#a#L:39-8#L:39#parseError(<eval>:39)
> >>>>>> at jdk.scripting.nashorn.scripts/jdk.nashorn.internal.scripts.S
> >>> cript$Recompilation$2359$\^eval\_$cu1$restOf.L:39-1#a#L:39-
> >>> 4#o#parse(<eval>:39)
> >>>>>> at jdk.scripting.nashorn.scripts/jdk.nashorn.internal.scripts.S
> >>> cript$Recompilation$2343$\^eval\_$cu1$restOf.L:39-1#a#L:39-
> >>> 8#L:39#p(<eval>:39)
> >>>>>> at jdk.scripting.nashorn.scripts/jdk.nashorn.internal.scripts.S
> >>> cript$Recompilation$2056$250675AA$\^eval\_.L:39-1#a#L:39-8#
> >>> L:39#T#L:39(<eval>:39)
> >>>>>> at jdk.scripting.nashorn.scripts/jdk.nashorn.internal.scripts.S
> >>> cript$Recompilation$1572$\^eval\_.:program(<eval>:41)
> >>>>>> at jdk.scripting.nashorn/jdk.nashorn.internal.runtime.ScriptFun
> >>> ctionData.invoke(ScriptFunctionData.java:652)
> >>>>>> at jdk.scripting.nashorn/jdk.nashorn.internal.runtime.ScriptFun
> >>> ction.invoke(ScriptFunction.java:513)
> >>>>>> at jdk.scripting.nashorn/jdk.nashorn.internal.runtime.ScriptRun
> >>> time.apply(ScriptRuntime.java:517)
> >>>>>> at jdk.scripting.nashorn/jdk.nashorn.api.scripting.NashornScrip
> >>> tEngine.evalImpl(NashornScriptEngine.java:420)
> >>>>>> ... 28 more
> >>>>>>
> >>>>>> ​
> >>>>>>
> >>>>>
> >>>>>
> >>>
> >>>
> >>
> 
> 



More information about the nashorn-dev mailing list