axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tom Jordahl <t...@macromedia.com>
Subject RE: bug report
Date Mon, 03 Nov 2003 21:03:00 GMT

Please file a bugzilla report.
This is a good enhancement.

Thanks!
--
Tom Jordahl


-----Original Message-----
From: Stefan.Ohrhallinger@bmi.gv.at
[mailto:Stefan.Ohrhallinger@bmi.gv.at]
Sent: Monday, November 03, 2003 6:54 AM
To: axis-dev@ws.apache.org
Subject: bug report


i think this might be a bug - not 100% sure so i´m not filing a bugzilla
report:
org.apache.axis.types.UnsignedLong doesn´t take very long values since it´s
converted to a double first, which has less bits

AXIS 1.1final (apparently not changed in CVS as of 2003-11-03)
JDK is: Classic VM (build 1.3.1, J2RE 1.3.1 IBM Windows 32 build
cn131-20021107 (JIT ena
bled: jitc))

TESTCASE:
(new
org.apache.axis.types.UnsignedLong("18446744073709551615")).toString().equal
s("18446744073709551615")
tests conversion max value of unsigned long and back -> fails

PATCH:
Index: UnsignedLong.java
===================================================================
RCS file:
/home/cvsuser/cvsroot/LibSources/org/apache/axis/types/UnsignedLong.java,v
retrieving revision 1.1
diff -u -r1.1 UnsignedLong.java
--- UnsignedLong.java	22 Oct 2003 11:26:30 -0000	1.1
+++ UnsignedLong.java	3 Nov 2003 14:02:11 -0000
@@ -54,20 +54,25 @@
  */
 package org.apache.axis.types;
 
-import org.apache.axis.utils.Messages;
+import java.math.*;
+import java.text.*;
 
-import java.text.FieldPosition;
-import java.text.NumberFormat;
+import org.apache.axis.utils.*;
 
 /**
  * Custom class for supporting primitive XSD data type UnsignedLong
  *
  * @author Chris Haddad <chaddad@cobia.net>
  * @see <a href="http://www.w3.org/TR/xmlschema-2/#unsignedLong">XML Schema
3.3.21</a>
+ * 2003-11-03 <stefan.ohrhallinger@bmi.gv.at> IEEE double precision is only
52 bit, therefore
+ * 			  not possible to set large unsigned long values as
double -> using BigInteger instead
  */
 public class UnsignedLong extends java.lang.Number implements
java.lang.Comparable {
-
-    protected Double lValue = new Double(0);
+	private static final BigInteger minValue =
+		new BigInteger("0");
+	private static final BigInteger maxValue =
+		new BigInteger("18446744073709551615");
+    protected BigInteger lValue = new BigInteger("0");
 
     public UnsignedLong() {
 
@@ -77,32 +82,32 @@
      * ctor for UnsignedLong
      * @exception NumberFormatException will be thrown if validation fails
      */
-    public UnsignedLong(double lValue) throws NumberFormatException {
+    public UnsignedLong(BigInteger lValue) throws NumberFormatException {
       setValue(lValue);
     }
 
     public UnsignedLong(String stValue) throws NumberFormatException {
-      setValue(Double.parseDouble(stValue));
+      setValue(new BigInteger(stValue));
     }
 
     /**
      *
      * validates the data and sets the value for the object.
      *
-     * @param long value
+     * @param BigInteger value
      */
-    public void setValue(double lValue) throws NumberFormatException {
+    public void setValue(BigInteger lValue) throws NumberFormatException {
         if (isValid(lValue) == false)
             throw new NumberFormatException(
                     Messages.getMessage("badUnsignedLong00") +
-                    String.valueOf(lValue) + "]");
-        this.lValue = new Double(lValue);
+                    lValue.toString() + "]");
+        this.lValue = lValue;
     }
 
     /**
-     * Format the Double in to a string
+     * Format the BigInteger in to a string
      */ 
-    private String convertDoubleToUnsignedLong(Double lValue) {
+    private String convertBigIntegerToUnsignedLong(BigInteger lValue) {
       if (lValue != null) {
           NumberFormat nf = NumberFormat.getInstance();
           nf.setGroupingUsed(false);
@@ -115,7 +120,7 @@
     }
 
     public String toString(){
-        return convertDoubleToUnsignedLong(lValue);
+        return lValue.toString();
     }
 
     public int hashCode(){
@@ -130,8 +135,9 @@
      * validate the value against the xsd definition
      *
      */
-    public boolean isValid(double lValue) {
-      if ( (lValue < 0L)  || (lValue > 18446744073709551615D) )
+    public boolean isValid(BigInteger lValue) {
+      if ( (lValue.compareTo(minValue) == -1)  ||
+      	(lValue.compareTo(maxValue) == 1 ))
         return false;
       else
         return true;


> - mfG Mag. Stefan Ohrhallinger
> Bundesministerium für Inneres
> Support-Unit ZMR, Tel: +43 1 31346 39162
> 

Mime
View raw message