some nashorn testing

Remi Forax forax at univ-mlv.fr
Tue Jan 8 13:56:14 PST 2013


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