I am attempting to build a JavaScript array in Java using the NativeArray
class from Mozilla Rhino. However, when I try to add elements to the NativeArray
, it throws a
java.lang.UnsupportedOperationException
.
Below is the code snippet:
NativeArray array = new NativeArray(1);
array.add("cccc");
The error received is as follows:
Caused by: java.lang.UnsupportedOperationException
at org.mozilla.javascript.NativeArray.add(NativeArray.java:1826)
If I create the NativeArray with a Java array from the start, everything works fine:
String[] str = new String[2];
str[0] = "aaaa";
str[1] = "bbbb";
NativeArray array = new NativeArray(str);
Upon inspecting the source code of NativeArray, I noticed that the add method always throws an error. The source code can be found here:
Please note: I am using version 1.7R4 of Mozilla Rhino, which is the latest version available.
Is this a bug within Mozilla Rhino or am I missing something in my implementation?
Thank you