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

java.text.NumberFormat.equals(null) throws NullPointerException

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      1.1.6
    • CPU:
      sparc
    • OS:
      solaris_2.5
    • Verification:
      Verified

      Backports

        Description



        Name: mgC56079 Date: 09/01/97



        The java.text.NumberFormat.equals(Object) method does not work correctly.
        This method should return false if called with null argument
        (see general contract for equals(): JLS 1.0 item 20.1.3, page 459).
        But it throws NullPointerException.

        Here is the test demonstrating the bug:

        -----------------NumberFormatEqualsNullTest.java------------------------
        import java.text.*;

        public class NumberFormatEqualsNullTest {

            public static void main (String args[]){

              try {
                System.out.println((new NumberFormatTest()).equals(null));
              } catch (NullPointerException e) {
                System.out.println("(new NumberFormatTest()).equals(null) throws unexpected exception");
              }
            }
        }

        class NumberFormatTest extends NumberFormat {
            public StringBuffer format(double number,
                                StringBuffer toAppendTo,
                                FieldPosition pos) {
              return new StringBuffer("");
            }
            public StringBuffer format(long number,
                                StringBuffer toAppendTo,
                                FieldPosition pos) {
              return new StringBuffer("");
            }
            public Number parse(String text, ParsePosition parsePosition) {
              return new Long(0);
            }
         }


           
        ---------Output from the test---------------------

        (new NumberFormatTest()).equals(null) throws unexpected exception

        --------------------------------------------------
           
        ======================================================================

          Attachments

            Issue Links

              Activity

                People

                Assignee:
                joconnersunw John Oconner (Inactive)
                Reporter:
                mgorshen Mikhail Gorshenev (Inactive)
                Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                  Dates

                  Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: