Longs aren't numbers in Java 8u162

Jesus Luzon jluzon at riotgames.com
Mon Apr 30 23:10:18 UTC 2018


This seems like it could be a side effect of a bug I reported where using a
number as the key in an object in Nashorn made an array of the at least the
size of the number and then inserted in the index of the number specified.
The bug was fixed around that version that you mention.

On Mon, Apr 30, 2018 at 3:38 PM, Ryan Berdeen <rberdeen at hubspot.com> wrote:

> I encountered an issue when upgrading from Java 8u66 to 8u162. In 8u66,
> java.lang.Integer and java.lang.Long both behaved as JS numbers. In 8u162
> (and 10.0.1), Longs behave differently in a way that is breaking my
> application.
>
>     function test(n) {
>       print(n);
>       print(typeof n);
>       print(n.hasOwnProperty('x'));
>       print();
>     }
>
>     test(new java.lang.Integer(0));
>     test(new java.lang.Long(0));
>
> In 8u66, this behaved the same for Integer and Long, but in 8u162, typeof
> returns "object", and the object doesn't have the expected properties:
>
>     $ jjs longs.js
>     0
>     number
>     false
>
>     0
>     object
>     longs.js:4 TypeError: n.hasOwnProperty is not a function
>
> In my application, this came up with values passed through to the engine in
> bindings.
>
> Is this change intentional? If so, is there a way to revert to the previous
> behavior and if not, is there a way to work around it so that I can update?
>


More information about the nashorn-dev mailing list