Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4232154

Very misleading error message from MessageFormat

XMLWordPrintable

    • beta
    • generic, x86, sparc
    • generic, solaris_2.6, windows_nt
    • Verified

      The original fault was mine, but the error message that came up is both
      grammatically either incomplete or incorrect, and fairly misleading anyway.

      I used a format string of "The date is {0:date}", using a ':' instead of ','.
      The message that is generated is
      java.lang.IllegalArgumentException: argument number too large at

      So, how many ways can I criticise this message....
      - It is not a problem with the argument number
      - The message either ends with unterminated "at", or if you read on to
        the stack trace in the next line, has an extraneous "at".
      - Reading the code, this message is generated even if the number is too small!
      Enough said?

      -- Jon


      import java.text.MessageFormat;
      import java.util.Date;

      public class toy {
          public static void main(String[] args) {
      System.err.println(MessageFormat.format("The date is {0:date}", new Object[] {new Date()}));
          }
      }


      java.lang.IllegalArgumentException: argument number too large at
              at java.text.MessageFormat.makeFormat(MessageFormat.java)
              at java.text.MessageFormat.applyPattern(MessageFormat.java)
              at java.text.MessageFormat.<init>(MessageFormat.java)
              at java.text.MessageFormat.format(MessageFormat.java)
              at toy.main(toy.java:6)




      Name: krC82822 Date: 09/09/2000


      java version "1.2.2"
      Classic VM (build JDK-1.2.2-001, native threads, symcjit)


      import java.text.MessageFormat;

      public class TestMessageFormat {

        public static void main(String [] args) {

          try {
            MessageFormat s = new MessageFormat("{0}{0}{0}{0}{0}{0}{0}{0}{0}{0}");
            System.out.println(s.format(args));
          } catch (Exception e) {
            e.printStackTrace();
          }

          try {
            // the following line causes the runtime exception
            MessageFormat s = new MessageFormat("{0}{0}{0}{0}{0}{0}{0}{0}{0}{0}{0}");
            System.out.println(s.format(args));
          } catch (Exception e) {
            e.printStackTrace();
          }
        }

      }

      causes the following runtime exception
      java.lang.IllegalArgumentException: argument number too large at
              at java.text.MessageFormat.makeFormat(MessageFormat.java:787)
              at java.text.MessageFormat.applyPattern(MessageFormat.java:321)
              at java.text.MessageFormat.<init>(MessageFormat.java:251)
              at com.rnix.test.TestMessageFormat.main(TestMessageFormat.java:17)
      (Review ID: 109332)
      ======================================================================
      Used TestMessageFormat.java to verify this bug, it works.

      ###@###.### 2001-09-24

            nlindenbsunw Norbert Lindenberg (Inactive)
            jjg Jonathan Gibbons
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: