JDK-8143896 : java.lang.Long is implicitly converted to double
  • Type: Bug
  • Component: core-libs
  • Sub-Component: jdk.nashorn
  • Affected Version: 8
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2015-11-24
  • Updated: 2017-06-27
  • Resolved: 2016-01-12
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
8u101Fixed 9 b102Fixed
Related Reports
Duplicate :  
Relates :  
Relates :  
This bug was reported by Tomas Hurka via mail.

On JDK 8, calling Long.valueOf("301077366599181567") and converting the result to string seems to convert the number to double since the result shows a loss of precision.

nashorn> java.lang.Long.valueOf("301077366599181567").toString()

If toString() would have been called on the java.lang.Long instance, the result should not loose precision and be the same as the input string.
The problem is that the lookup of "toString" on the java.lang.Long instance is handled by the NashornPrimitiveLinker (which is a prioritized linker), not the BeansLinker. Therefore, we end up calling Number.prototype.toString() instead of java.lang.Long.toString().