Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-1266582

The java.sql.Numeric.createFromScaled() method does not work with large scales

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P1 P1
    • 1.1
    • 1.0.2
    • core-libs
    • 1.1
    • sparc
    • solaris_2.5
    • Not verified



      Name: saf@russia Date: 09/05/96


      This bug was found by St.Petersburg Java SQE team (by Mikhail Gorshenev).

      The java.sql.Numeric.createFromScaled(long scaled, int s) method works wrong
      with large or negative scales.

      The java.sql specification (JDBC version 1.01) says the following:
      " public static Numeric createFromScaled(long scaled,
                                               int s)
            Return a numeric value created by dividing the argument by 10**scale.
            Thus, createFromScaled(504,2) would create the value "5.04".
            Parameters:
                  scaled - The scaled value as a long.
                  s - The desired scale value
            Returns:
                  A new numeric. "

      Here is the minimized test demonstrating the bug:
      ------ java_sql_Numeric_createFromScaled.java -------
      import java.sql.Numeric;
      class java_sql_Numeric_createFromScaled {
        public static void main(String argv[]) {
            Numeric n1 = Numeric.createFromScaled(1,20);
                     //should create "0.00000000000000000001" but creates "1"
            System.out.println("Scaled value: " + n1);
            Numeric n2 = Numeric.createFromScaled(1,-2);
                     //should create "100" but throws exception
            System.out.println("Scaled value: " + n2);
        }
      }

      ----- The output of the test: -------------------------
      Scaled value: 1
      java.lang.ArrayIndexOutOfBoundsException: 13
      at java.sql.Numeric.toString(Numeric.java:544)
      at java.lang.StringBuffer.append(StringBuffer.java)
      at java_sql_Numeric_createFromScaled.main(java_sql_Numeric_createFromScaled.java:9)
      -------------------------------------------------------


      Workaround:
      None
      ======================================================================

            mhapnersunw Mark Hapner (Inactive)
            duke J. Duke
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: