Hello Pekka, Mon, 6 Dec 2010 22:36:18 +0200 Pekka Enberg <penb...@kernel.org>:
> Hi Ivan, > > 2010/12/6 Ivan Maidanski <iv...@mail.ru>: > >> > 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. > >> > >> I'm not able to reproduce the desired behavior with Sun JRE: > > > > I repeat: Note, however, that the test does NOT print the expected > "12" on Sun JRE 6 > > > > with Sun JRE: it prints 1234567890 > > with Classpath: 1234 > > with Classpath+this_patch: 12 > > Oh, right. Sorry abut that. I can indeed reproduce the behavior described > above. > > > I could simulate Sun JRE behavior but the author of the Classpath > DecimalFormat.parse() implementation (IMHO) wanted setMaximumIntegerDigits() > to act as expected. Any opinion what way should we follow? > > I'm not a Classpath developer so my opinion doesn't matter that much. How many Classpath developers can you remember that have been active in the mailing list recently? :( > I'm bit surprised, though, that we'd want behavior that doesn't > match > Sun JRE. To me, any API behavior (even if it's a bug) that has lived > long enough in Sun JRE is what Classpath ought to aim at. > Compatibility is not just following the specification but also taking > real-world wrinkles into account. I agree with you but: 1. today we have an opportunity to hack (influence) OpenJDK (what should the correct behavior of setMaximumDigits() be in the future JDK releases?); 2. The current Classpath implementation of DecimalFormat.parse() (returning 4 digits in the above test case) is anyway broken, so it's ok to fix it somehow now (nothing prevents to remove stop position in the code to match the RI later). > > Pekka Regards.