Closed
Bug 164308
Opened 22 years ago
Closed 22 years ago
Wrong documentation of LiveConnect JS-to-Java conversion of NaN
Categories
(Documentation Graveyard :: Web Developer, defect)
Tracking
(Not tracked)
VERIFIED
FIXED
People
(Reporter: pschwartau, Assigned: bc)
References
()
Details
The given URL is part of our LiveConnect documentation. Under the
section JavaScript to Java Conversions > Number Conversion, it states:
"NaN values are converted to zero"
This is not correct; see bug 163817,
"LiveConnect JavaScript to Java Data Type Conversion Error"
From the discussion in that bug, it was decided that the correct
behavior is for LiveConnect to throw an error on this conversion
for most Java numerical types. The exceptions are for Java types
float and double, for which LiveConnect converts NaN to NaN:
------- Additional Comment_ #17 From Phil Schwartau 2002-08-22 11:31 -------
In the latest edition (Edition 4, January 2002), Flanagan give the same
treatment as in Edition 3. He explains that the JavaScript number type
can convert to Java numerical types like byte, short, int, etc.,
but without mentioning any rules for edge cases like NaN.
Here is what the LiveConnect shell does on various conversions of NaN.
It errors for Byte, Short, Integer, Long. It succeeds for Float and Double:
js> java.lang.Byte.toString(NaN)
InternalError: Unable to convert JavaScript value NaN to Java value of type byte
js> java.lang.Short.toString(NaN)
InternalError: Unable to convert JavaScript value NaN to Java value of type short
js> java.lang.Integer.toString(NaN)
InternalError: Unable to convert JavaScript value NaN to Java value of type int
js> java.lang.Long.toString(NaN)
InternalError: Unable to convert JavaScript value NaN to Java value of type long
js> java.lang.Float.toString(NaN)
NaN
js> java.lang.Double.toString(NaN)
NaN
------- Additional Comment_ #19 From Tim 2002-08-22 12:24 -------
Note that Java has constants to represent NaN (and other fun non-numbers)
in floats and doubles (Float.NaN and Double.NaN of type |float| and |double|,
respectively); no such constants exist for other numerical types.
Reporter | ||
Comment 1•22 years ago
|
||
NOTES:
1. I don't know what other URLs might have the same error; I'll leave
that to the Documentation group
2. I'm not a Java expert, but I see that |char| is another Java
numerical datatype. I was unable to illustrate it with the
other numerical datatypes above, because |java.lang.Char|
doesn't seem to have a toString() method as the others do.
So I shouldn't have introduced toString() into the issue.
Here is a better illustration. Notice again the different
behavior for the Java float and double types:
js> java.lang.Byte(NaN)
InternalError: Unable to convert JavaScript value NaN to Java value of type byte
js> java.lang.Short(NaN)
InternalError: Unable to convert JavaScript value NaN to Java value of type short
js> java.lang.Integer(NaN)
InternalError: Unable to convert JavaScript value NaN to Java value of type int
js> java.lang.Long(NaN)
InternalError: Unable to convert JavaScript value NaN to Java value of type long
js> java.lang.Float(NaN)
NaN
js> java.lang.Double(NaN)
NaN
js> java.lang.Character(NaN)
InternalError: Unable to convert JavaScript value NaN to Java value of type char
Assignee | ||
Comment 2•22 years ago
|
||
updating url to current location. If you want to assign this to me, I will take
care of it.
Assignee | ||
Comment 4•22 years ago
|
||
Phil, can you review:
http://elwood.netscape.com:10050/library/manuals/2000/javascript/1.5/guide/lc.html#1037125
and tell me if it is accurate/sufficient? I would like to push this to DevEdge
Friday and need to know by Wednesday (Thursday at the latest).
No longer blocks: 206365
Status: NEW → ASSIGNED
Reporter | ||
Comment 5•22 years ago
|
||
Bob: the data looks good. I do have a couple stylistic suggestions:
I. In the rows for |double| and |float|, the line "NaN is converted to NaN"
appears without any margin space above it. I think it should have space above,
the way it does in the row for |byte char int etc.|
II. I think it would be great if the font for these headers could be
bolded and increased in size:
JavaScript to Java Conversions
Java to JavaScript Conversions
Assignee | ||
Comment 6•22 years ago
|
||
Ok, I think I fixed this.
I cleaned up the reference markup but not the guide markup yet. It is a bit
confusing will all the font and Z* tag foo in the file.
We can work on presentation a bit more after I clean it up and move it to CSS
based preso like the new reference.
Assignee | ||
Comment 7•22 years ago
|
||
f
Status: ASSIGNED → RESOLVED
Closed: 22 years ago
Resolution: --- → FIXED
You need to log in
before you can comment on or make changes to this bug.
Description
•