Hi,

Sorry for the provided test below - it doesn't test the things that are fixed 
by the attached patch. In fact, the test is for a bug that has been already 
fixed since Classpath v0.93 (by not relying on setMaximumIntegerDigits 
implementation). So, the correct test is:

import java.text.*;
import java.util.*;
public class DecimalFormatTest {
  public static void main(String[] args) throws ParseException {
    NumberFormat numberFormat = NumberFormat.getInstance(Locale.getDefault());
    numberFormat.setGroupingUsed (false);
    numberFormat.setParseIntegerOnly (true);
    numberFormat.setMaximumFractionDigits (0);
    int fmt_count = 2;
    numberFormat.setMinimumIntegerDigits(fmt_count);
    numberFormat.setMaximumIntegerDigits(fmt_count);
    System.out.println(numberFormat.parse("1234567890")); // should print "12"
  }
}

It tests the following code change (by the attached patch) in 
DecimalFormat.parse():

    int stop = start + this.maximumIntegerDigits + maximumFractionDigits + 2;
    if (useExponentialNotation)
      stop += minExponentDigits + 1;

->

    int stop = start + maximumIntegerDigits;
    if (maximumFractionDigits > 0)
      stop += maximumFractionDigits + 1;
     if (useExponentialNotation)
      stop += (minExponentDigits > 0 ? minExponentDigits : 1) + 2;


Note, however, that the test does not print the expected "12" on Sun JRE 6.

Regards.

Thu, 04 Nov 2010 17:18:32 +0300 Ivan Maidanski <iv...@mail.ru>:

> Hi!
> 
> This is the patch (against the current Classpath snapshot) fixing some bugs in
> Decimal/SimpleDateFormat.parse().
> 
> Here is just one test case (only for the bug related to 'stop' local
> var value incorrect computing; this test case was kindly supplied by Vasiliy
> Khayrulin <siria...@gmail.com>):
> 
> import java.text.*;
> import java.util.*;
> public class SimpleDateFormatTest {
> public static void main(String[] args) throws ParseException {
> SimpleDateFormat dateF = new SimpleDateFormat("yyyyMMddHHmmssz");
> dateF.setTimeZone(new SimpleTimeZone(0, "Z"));
> System.out.println(dateF.parse("20101005034343GMT+00:00"));
> }
> }
> 
> ChangeLog entries:
> * java/text/SimpleDateFormat.java: (CompiledField,
> CompiledField.field, CompiledField.character): Make final.
> * java/text/DecimalFormat.java: (attributes): Likewise.
> * java/text/SimpleDateFormat.java: (CompiledField,
> translateLocalizedPattern(String,String,String), withLeadingZeros(int,
> int,FormatBuffer), expect(String,ParsePosition, char),
> computeOffset(String,ParsePosition)): Make the private entity static.
> * java/text/DecimalFormat.java: (equals(String,String),
> patternChars(DecimalFormatSymbols), quoteFix(String,String)): Likewise.
> * java/text/SimpleDateFormat.java: (CompiledField(int,int,char),
> CompiledField.getField(), CompiledField.getSize(),
> CompiledField.getCharacter()): Make package-private (instead of
> public).
> (parse(String, ParsePosition)): Apply numberFormat.parse() to
> dateStr substring only if dateStr has enough length; apply
> numberFormat.parse() to dateStr starting from its beginning (instead
> of pos position) so not to adjust pos before and after that call;
> don't test pos for null value; if n is non-null but not of Long type
> then set error position before returning null; use String
> regionMatches() instead of toUpperCase().startsWith().
> (computeOffset(String,ParsePosition)): Treat null returned by
> matcher.group(3) as the empty string; refine the documentation.
> * java/text/DecimalFormat.java: (minExponentDigits): Fix comment typo.
> (parse(String, ParsePosition)): Use String startsWith() instead of
> contains(); adjust pos index before returning; don't use (remove)
> isPositive, hasPositiveSuffix and positiveEqualsNegative local
> variables; set positiveLen and negativeLen local variables only if
> needed; don't reassign isNegative local variable to the same value;
> handle infinity case before building number value; fix stop local
> variable value computing (for the case when no fraction part and for
> the case of useExponentialNotation reserving also the space for 'E'
> symbol); increment i in 'for' clause (making the algorithm a bit more
> clearer) instead of incrementing it after chatAt() and decrementing it
> at break; handle the cases (when building number) of zero, exponent
> and minus symbols are not equal to '0', 'e' and '-',
> respectively;
> don't allow exponent symbol unless useExponentialNotation and the
> exponent part is not seen yet; allow minus symbol (when building
> number value) only for the exponent part; don't test i value to be the
> same as start one in addition to the empty number string test; use
> String regionMatches() instead of endsWith() when testing for the
> suffix; adjust pos index properly (taking into account the suffix
> length).
> 
> Regards.


Reply via email to