some nashorn testing

Marcus Lagergren marcus.lagergren at oracle.com
Tue Jan 8 23:45:21 PST 2013


Remi, Andreas

I can't reproduce your problem running 

java -jar nashorn.jar script.js

where script.js is 

--
 var array;
 try {
   array = new (Java.type("java.lang.Object[]"))(len);
 } catch (x) {
   array = [];
 }
--

Do you have a reproducer you can send me ? I know there was a bug regarding array literal types just before Christmas, but it's in the openjdk as far as I can tell.

Regards
Marcus


On Jan 8, 2013, at 10:56 PM, Remi Forax <forax at univ-mlv.fr> wrote:

> On 01/08/2013 10:49 PM, Attila Szegedi wrote:
>> Hey Marcus and Jim, this is similar to that bug we saw before with array literals in the ternary operator. Something related to codegen's inference of types…
> 
> a simple workaround is to change the last line
> 
>  var array;
>  try {
>    array = new (Java.type("java.lang.Object[]"))(len);  // array is Object[]
>  } catch (x) {
>    //array = [];                                        // array is NativeArray
>    array = new (Java.type("java.lang.Object[]"))(0);    // array is Object[]
>  }
> 
> Rémi
> 
>> 
>> On Jan 8, 2013, at 9:30 PM, Andreas Rieber <rieberandreas at gmail.com> wrote:
>> 
>>> I tried some cases and will go for (Nashorn and Rhino):
>>> 
>>>   var array;
>>>   try {
>>>     array = new (Java.type("java.lang.Object[]"))(len);
>>>   } catch (x) {
>>>     array = [];
>>>   }
>>> 
>>> The catch block works with Rhino but gives with Nashorn:
>>> 
>>> Exception in thread "main" java.lang.ClassCastException: Cannot cast jdk.nashorn.internal.objects.NativeArray to [Ljava.lang.Object;
>>>     at sun.invoke.util.ValueConversions.newClassCastException(ValueConversions.java:461)
>>>     at sun.invoke.util.ValueConversions.castReference(ValueConversions.java:456)
>>>     at jdk.nashorn.internal.scripts.Script$main.sprintf(main.js:114)
>>>     at jdk.nashorn.internal.runtime.ScriptFunction.invoke(ScriptFunction.java:350)
>>>     at jdk.nashorn.internal.runtime.ScriptRuntime.apply(ScriptRuntime.java:310)
>>>     at jdk.nashorn.internal.objects.NativeFunction.apply(NativeFunction.java:133)
>>> 
>>> 
>>> cheers
>>> Andreas
>>> 
> 



More information about the nashorn-dev mailing list