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

java.lang.NullPointerException when formatting pattern with MessageFormat class

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      1.1.6
    • CPU:
      x86
    • OS:
      windows_95
    • Verification:
      Verified

      Backports

        Description



        Name: tb29552 Date: 08/27/97


        The following fragment shows the exception thrown :

        import java.text.*;

        class Test {
            public static void main(String[] args) {
                String[] pattern = {"Message without param",
                                    "Message with param:{0}",
                                    "Longer Message with param {0}"};
                //difference between the two param strings are that
                //in the first one, the param position is within the
                //length of the string without param while it is not so
                //in the other case.

                MessageFormat messageFormatter = new MessageFormat("");

                //Apply pattern with param and print the result
                messageFormatter.applyPattern(pattern[1]);
                Object[] params = {new String("BUG")};
                System.out.println(messageFormatter.format(params));

                //Apply pattern without param and print the result
                messageFormatter.applyPattern(pattern[0]);
                System.out.println(messageFormatter.format(null));
                     //This statement gives an exception while formatting...
                     //If we use pattern[1] for the message with param,
                     //we get an NullPointerException in MessageFormat.java(617)
                     //If we use pattern[2] for the message with param,
                     //we get an StringArrayIndexOutOfBoundsException in MessageFormat.java(614)
                     //Both are due to maxOffset not being reset to -1
                     //in applyPattern() when the pattern does not
                     //contain any param.
            }
        }


        company - Aztec Software , email - ###@###.###
        ======================================================================

          Attachments

            Issue Links

              Activity

                People

                Assignee:
                joconnersunw John Oconner (Inactive)
                Reporter:
                tbell Tim Bell
                Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                  Dates

                  Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: