JDK-4134300 : DecimalFormat bug added in 1.1.6
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.text
  • Affected Version: 1.1.6,1.2.0
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • OS:
    generic,solaris_2.5,windows_95,windows_nt generic,solaris_2.5,windows_95,windows_nt
  • CPU: generic,x86,sparc
  • Submitted: 1998-05-01
  • Updated: 1999-01-15
  • Resolved: 1999-01-15
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.
Other Other
1.1.7 b01Fixed 1.2.0Fixed
Related Reports
Duplicate :  
Duplicate :  
Duplicate :  
Duplicate :  
Duplicate :  
Duplicate :  
Description

Name: el35337			Date: 05/01/98


import java.text.*;

/*
JDK 1.1.6 Bug, did NOT occur in 1.1.5
Possibly related to bug 4125885.

This class demonstrates a regression in version 1.1.6
of DecimalFormat class.

1.1.6 Results
Value 1.2 Format #.00 Result '01.20'      !!!wrong
Value 1.2 Format 0.00 Result '001.20'     !!!wrong
Value 1.2 Format 00.00 Result '0001.20'   !!!wrong
Value 1.2 Format #0.0# Result '1.2'
Value 1.2 Format #0.00 Result '001.20'    !!!wrong

1.1.5 Results
Value 1.2 Format #.00 Result '1.20'
Value 1.2 Format 0.00 Result '1.20'
Value 1.2 Format 00.00 Result '01.20'
Value 1.2 Format #0.0# Result '1.2'
Value 1.2 Format #0.00 Result '1.20'
*/

public class JDK116Bug
{
  public static void main(String[] args)
  {
    show(1.2, "#.00");
    show(1.2, "0.00");
    show(1.2, "00.00");
    show(1.2, "#0.0#");
    show(1.2, "#0.00");
  }
  
  private static void show(double d, String s)
  {
    String result = new DecimalFormat(s).format(d);
    System.out.println("Value " + d + " Format " + s
       + " Result '" + result + "'");
  }
}
(Review ID: 29357)
======================================================================

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: 1.1.7 FIXED IN: 1.1.7 INTEGRATED IN: 1.1.7 1.2fcs
14-06-2004

SUGGESTED FIX (See attached DecimalFormat.java.Z supplied by Alan Liu of IBM/Taligent.) mark.son-bell@eng 1998-05-11 joseph.kowalski@Eng 1998-05-14 Since a lot of people will be trying to understand the impact of this change, I'm including the diffs for "ease of use" of this bug report.... *************** *** 1,10 **** /* ! * @(#)DecimalFormat.java 1.36 98/02/19 * * (C) Copyright Taligent, Inc. 1996 - All Rights Reserved * (C) Copyright IBM Corp. 1996 - All Rights Reserved * ! * Portions copyright (c) 1996 Sun Microsystems, Inc. All Rights Reserved. * * The original version of this source code and documentation is copyrighted * and owned by Taligent, Inc., a wholly-owned subsidiary of IBM. These --- 1,10 ---- /* ! * @(#)DecimalFormat.java 1.37 98/04/22 * * (C) Copyright Taligent, Inc. 1996 - All Rights Reserved * (C) Copyright IBM Corp. 1996 - All Rights Reserved * ! * Portions copyright (c) 1996-1998 Sun Microsystems, Inc. All Rights Reserved. * * The original version of this source code and documentation is copyrighted * and owned by Taligent, Inc., a wholly-owned subsidiary of IBM. These *************** *** 178,184 **** * @see java.util.Format * @see java.util.NumberFormat * @see java.util.ChoiceFormat ! * @version 1.36 02/19/98 * @author Mark Davis * @author Alan Liu */ --- 178,184 ---- * @see java.util.Format * @see java.util.NumberFormat * @see java.util.ChoiceFormat ! * @version 1.37 04/22/98 * @author Mark Davis * @author Alan Liu */ *************** *** 1490,1506 **** // Handle patterns with no '0' pattern character. These patterns // are legal, but must be interpreted. "##.###" -> "#0.###". // ".###" -> ".0##". ! if (zeroDigitCount == 0 && digitLeftCount > 0) ! { ! if (decimalPos >= 0) // Handle "###.###" and "###." and ".###" ! { ! int n = decimalPos; ! if (n == 0) ++n; // Handle ".###" ! digitRightCount = digitLeftCount - n; ! digitLeftCount = n - 1; ! } ! else --digitLeftCount; // Handle "###" ! zeroDigitCount = 1; } // Do syntax checking on the digits. --- 1490,1510 ---- // Handle patterns with no '0' pattern character. These patterns // are legal, but must be interpreted. "##.###" -> "#0.###". // ".###" -> ".0##". ! /* We allow patterns of the form "####" to produce a zeroDigitCount of ! * zero (got that?); although this seems like it might make it possible ! * for format() to produce empty strings, format() checks for this ! * condition and outputs a zero digit in this situation. Having a ! * zeroDigitCount of zero yields a minimum integer digits of zero, which ! * allows proper round-trip patterns. That is, we don't want "#" to ! * become "#0" when toPattern() is called (even though that's what it ! * really is, semantically). */ ! if (zeroDigitCount == 0 && digitLeftCount > 0 && ! decimalPos >= 0) { // Handle "###.###" and "###." and ".###" ! int n = decimalPos; ! if (n == 0) ++n; // Handle ".###" ! digitRightCount = digitLeftCount - n; ! digitLeftCount = n - 1; ! zeroDigitCount = 1; } // Do syntax checking on the digits. *************** *** 1519,1532 **** this.negativePrefix = positivePrefix; // assume these for now this.negativeSuffix = positiveSuffix; int digitTotalCount = digitLeftCount + zeroDigitCount + digitRightCount; ! setMinimumIntegerDigits(decimalPos >= 0 ? (decimalPos - digitLeftCount) : 0); ! // Handles the "0000" like patterns by recording the correct decimal ! // position. HShih ! if (zeroDigitCount > 1 && digitLeftCount == 0 && digitRightCount == 0) ! setMinimumIntegerDigits(zeroDigitCount); ! // Handles "#,##0" and "#,000" correctly ! else if (zeroDigitCount > 0 && digitLeftCount > 0 && zeroDigitCount != digitLeftCount && (digitTotalCount == digitLeftCount + zeroDigitCount)) ! setMinimumIntegerDigits(zeroDigitCount); setMaximumIntegerDigits(useExponentialNotation ? digitLeftCount + getMinimumIntegerDigits() : 127); setMaximumFractionDigits(decimalPos >= 0 ? (digitTotalCount - decimalPos) : 0); --- 1523,1533 ---- this.negativePrefix = positivePrefix; // assume these for now this.negativeSuffix = positiveSuffix; int digitTotalCount = digitLeftCount + zeroDigitCount + digitRightCount; ! /* The effectiveDecimalPos is the position the decimal is at or ! * would be at if there is no decimal. Note that if decimalPos<0, ! * then digitTotalCount == digitLeftCount + zeroDigitCount. */ ! int effectiveDecimalPos = decimalPos >= 0 ? decimalPos : digitTotalCount; ! setMinimumIntegerDigits(effectiveDecimalPos - digitLeftCount); setMaximumIntegerDigits(useExponentialNotation ? digitLeftCount + getMinimumIntegerDigits() : 127); setMaximumFractionDigits(decimalPos >= 0 ? (digitTotalCount - decimalPos) : 0);
11-06-2004

PUBLIC COMMENTS This bug is not reproducible in 1.2beta4E, but has been confirmed as a regression from 1.1.5 in 1.1.6. A fix is available.
10-06-2004

EVALUATION This bug cannot be reproduced in 1.2b4. It may be a duplicate of 4134034. The enclosed test passes on the latest build. NOTE: Not yet evaluated on 1.1.6. laura.werner@eng 1998-05-11 This is indeed a bug in 1.1.6. The attachment DecimalFormat.java.Z provides a workaround which will be integrated in the next dotdot release. mark.son-bell@eng 1998-05-11
11-05-1998