Don't lose precision on a java.lang.Long passed to a long parameter

RESOLVED FIXED in 1.6R6

Status

Rhino
Core
RESOLVED FIXED
11 years ago
11 years ago

People

(Reporter: Norris Boyd, Assigned: Norris Boyd)

Tracking

1.6R5
1.6R6
x86
Linux

Details

(Assignee)

Description

11 years ago
Currently a primitive long works but a java.lang.Long doesn't. Here's a shell session with debugging on to show overloading behavior:

js> var l = java.lang.Long.parseLong("1111111111111111", 16)
 ----- Found first applicable java.lang.Long.parseLong(java.lang.String,int) for arguments (string,number)
 ----- Calling java.lang.Long.parseLong (java.lang.String,int) for arguments (string,number)
 ----- Returned 1229782938247303441 actual = class java.lang.Long expect = long
 ----- Wrapped as 1229782938247303441 class = class java.lang.Long
js> var L = new java.lang.Long(l)
 ----- Found first applicable java.lang.Long.(long) for arguments (number)
 ----- Rejecting (all current bests better) java.lang.Long.(java.lang.String) for arguments (number)
js> java.lang.Long.bitCount (l)
 ----- Found java.lang.Long.bitCount(long) for arguments (number)
 ----- Calling java.lang.Long.bitCount(long) for arguments (number)
 ----- Returned 16 actual = class java.lang.Integer expect = int
 ----- Wrapped as 16 class = class java.lang.Integer
16
js> java.lang.Long.bitCount(L)
 ----- Found java.lang.Long.bitCount(long) for arguments (java.lang.Long)
 ----- Calling java.lang.Long.bitCount(long) for arguments (number)
 ----- Returned 14 actual = class java.lang.Integer expect = int
 ----- Wrapped as 14 class = class java.lang.Integer
14
js>

However, with my proposed change, I get

js> var l = java.lang.Long.parseLong("1111111111111111", 16)
 ----- Found first applicable java.lang.Long.parseLong(java.lang.String,int) for arguments (string,number)
 ----- Calling java.lang.Long.parseLong(java.lang.String,int) for arguments (string,number)
 ----- Returned 1229782938247303441 actual = class java.lang.Long expect = long
 ----- Wrapped as 1229782938247303441 class = class java.lang.Long
js> var L = new java.lang.Long(l)
 ----- Found first applicable java.lang.Long.(long) for arguments (number)
 ----- Rejecting (all current bests better) java.lang.Long.(java.lang.String) for arguments (number)
js> java.lang.Long.bitCount(L)
 ----- Found java.lang.Long.bitCount(long) for arguments (java.lang.Long)
 ----- Calling java.lang.Long.bitCount(long) for arguments (number)
 ----- Returned 16 actual = class java.lang.Integer expect = int
 ----- Wrapped as 16 class = class java.lang.Integer
16
(Assignee)

Comment 1

11 years ago
Fixed:

Checking in NativeJavaObject.java;
/cvsroot/mozilla/js/rhino/src/org/mozilla/javascript/NativeJavaObject.java,v  <-- NativeJavaObject.java
new revision: 1.77; previous revision: 1.76
done
Status: NEW → RESOLVED
Last Resolved: 11 years ago
Resolution: --- → FIXED
(Assignee)

Comment 2

11 years ago
Adding target milestone of 1.6R6 based on the date this bug was resolved FIXED.
Target Milestone: --- → 1.6R6
You need to log in before you can comment on or make changes to this bug.