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

java.text.setMaximumIntegerDigits works incorrectly.

    XMLWordPrintable

Details

    • 1.2beta4
    • sparc
    • solaris_2.5
    • Verified

    Description



      Name: dfC67450 Date: 02/10/98



      java.text.setMaximumIntegerDigits takes into account only the
      lowest 8 bits of the argument.

      The bug causes the following JCK-12beta2 test to fail:

      api/java_text/NumberFormat/manual.html#SetGet


      Here is the test demonstrating the bug:

      -----------------TestNF.java------------------------
      import java.text.*;

      public class TestNF {
          public static void main (String args[]){
              NumberFormat nf = NumberFormat.getInstance();
              nf.setMaximumIntegerDigits(128);
              System.out.println("setMaximumIntegerDigits(128)");
              System.out.println("getMaximumIntegerDigits() returns " + nf.getMaximumIntegerDigits());
          }
      }

      ---------Output from the test---------------------
      setMaximumIntegerDigits(128)
      getMaximumIntegerDigits() returns -128
      --------------------------------------------------

      Javadoc is silent about range of input values which the
        java.text.NumberFormat.setMaximumIntegerDigits(int newValue),
        java.text.NumberFormat.setMinimumIntegerDigits(int newValue),
        java.text.NumberFormat.setMaximumFractionDigits(int newValue),
        java.text.NumberFormat.setMinimumFractionDigits(int newValue)

      allow. (See 4075780) These methods shouldn't probably convert
      int to byte.

      Here is the fragment of source code for setMaximumIntegerDigits method:

          /**
           * Sets the maximum number of digits allowed in the integer portion of a
           * number. maximumIntegerDigits must be >= minimumIntegerDigits. If the
           * new value for maximumIntegerDigits is less than the current value
           * of minimumIntegerDigits, then minimumIntegerDigits will also be set to
           * the new value.

           * @see #getMaximumIntegerDigits
           */
          public void setMaximumIntegerDigits(int newValue) {
              maxIntegerDigits = (byte) Math.max(0,Math.min(newValue,308));
              if (minIntegerDigits > maxIntegerDigits)
                  minIntegerDigits = maxIntegerDigits;
          }




      ======================================================================

      Attachments

        Activity

          People

            duke J. Duke
            dfazunensunw Dmitri Fazunenko (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: