RI's java.util.Formatter has inconsistent behavior on incompatible flags handling: different kind of conversions has similar spec on this issue, which only cover one flag "#" - "If the '#' flag is given, then a FormatFlagsConversionMismatchException will be thrown", and most kind of conversions in RI ignore other incompatible flags, but there is one kind of conversion named as "general conversion" throws exception on all incompatible flags.

For example, the sign flag of "+" is incompatible with both character conversion and general conversion, and character conversion ignore it while general conversion throws exception, the test case below shows the difference:

public class FormatterTest extends TestCase {
   public void testFormat() {
       Formatter f = new Formatter(Locale.US);
       //Character conversion, incompatible flag "+" is ignored
       f.format("%+c", 'W');
       assertEquals("W", f.toString());

       f = new Formatter(Locale.US);
       try {
           //General conversion, incompatible flag "+" is reported
           f.format("%+h", "hello");
           fail("FormatFlagsConversionMismatchException is thrown on RI");
       } catch (FormatFlagsConversionMismatchException e) {
           // expected
       }
   }
}

Should we consider RI's behavior is not logical? or just make Harmony comply with RI?

--
Paulex Yang
China Software Development Lab
IBM



---------------------------------------------------------------------
Terms of use : http://incubator.apache.org/harmony/mailing.html
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to