JDK-6481179 : Bug when reporting IllegalArgumentException for "unknown format type"
  • Type: Bug
  • Status: Closed
  • Resolution: Fixed
  • Component: core-libs
  • Sub-Component: java.text
  • Priority: P4
  • Affected Version: 5.0
  • OS: windows_xp
  • CPU: x86
  • Submit Date: 2006-10-12
  • Updated Date: 2011-03-08
  • Resolved Date: 2011-03-08
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 Availabitlity Release.

To download the current JDK release, click here.
JDK 7
7 b03Fixed
Description
FULL PRODUCT VERSION :
java version "1.5.0_08"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_08-b03)
Java HotSpot(TM) Client VM (build 1.5.0_08-b03, mixed mode, sharing)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]

EXTRA RELEVANT SYSTEM CONFIGURATION :
no required.

A DESCRIPTION OF THE PROBLEM :
After testing java.text.MessageFormat, I got several errors but one of them waas inconsistent.
Checking into src.zip, I realized that in method:
private void makeFormat(int position, int offsetNumber, StringBuffer[] segments)
At line 1433 "IllegalArgumentException" is thrown as follows:
        default:
            maxOffset = oldMaxOffset;
            throw new IllegalArgumentException("unknown format type at ");
        }
It should be:
        default:
            maxOffset = oldMaxOffset;
            throw new IllegalArgumentException("unknown format type at "+<theIndexOrPosition>);
        }

Just like in line 1330 and 1333:
        try {
            argumentNumber = Integer.parseInt(segments[1].toString()); // always unlocalized!
        } catch (NumberFormatException e) {
            throw new IllegalArgumentException("can't parse argument number " + segments[1]);
        }
        if (argumentNumber < 0) {
            throw new IllegalArgumentException("negative argument number " + argumentNumber);
        }


STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
MessageFormat.format(
    "This is a message: {1,asdf}",
    new Object[] {"val0", "val1" }
)


EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Message should include position:
Exception in thread "main" java.lang.IllegalArgumentException: unknown format type at <POSITION>
	at java.text.MessageFormat.makeFormat(MessageFormat.java:1433)
	at java.text.MessageFormat.applyPattern(MessageFormat.java:450)
	at java.text.MessageFormat.<init>(MessageFormat.java:350)
	at java.text.MessageFormat.format(MessageFormat.java:803)
	at test.Test.breakMessageFormat(Test.java:134)
	at test.Test.main(Test.java:76)
ACTUAL -
Message does not include position:
Exception in thread "main" java.lang.IllegalArgumentException: unknown format type at
	at java.text.MessageFormat.makeFormat(MessageFormat.java:1433)
	at java.text.MessageFormat.applyPattern(MessageFormat.java:450)
	at java.text.MessageFormat.<init>(MessageFormat.java:350)
	at java.text.MessageFormat.format(MessageFormat.java:803)
	at test.Test.breakMessageFormat(Test.java:134)
	at test.Test.main(Test.java:76)

ERROR MESSAGES/STACK TRACES THAT OCCUR :
Exception in thread "main" java.lang.IllegalArgumentException: unknown format type at
	at java.text.MessageFormat.makeFormat(MessageFormat.java:1433)
	at java.text.MessageFormat.applyPattern(MessageFormat.java:450)
	at java.text.MessageFormat.<init>(MessageFormat.java:350)
	at java.text.MessageFormat.format(MessageFormat.java:803)
	at test.Test.breakMessageFormat(Test.java:134)
	at test.Test.main(Test.java:76)

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
public class Test {
    public static void main(String[] p_args) {
        MessageFormat.format(
            "This is a message: {1,asdf}", new Object[] {"val0", "val1" }
        )
    }
}

---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
No workarounds.

Comments
EVALUATION The given format type should be displayed. This bug will be fixed in jdk7. Thank you for catching this bug.
2006-10-16