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

ListResourceBundle.handleGetObject(null) does not throw NPE

XMLWordPrintable



      Name: auR10023 Date: 06/28/2001


      ListResourceBundle.handleGetObject() does not throw NullPointerException
      with null key.

      The javadoc says:
      ...
      public final Object handleGetObject(String key)
         
           Description copied from class: ResourceBundle
           Gets an object for the given key from this resource bundle. Returns
      null if this resource bundle does not contain an object for the
           given key.

           Specified by:
               handleGetObject in class ResourceBundle
           Following copied from class: java.util.ResourceBundle
           Parameters:
               key - the key for the desired object
           Returns:
               the object for the given key, or null
           Throws:
               NullPointerException - if key is null
      ...

      Here is the example:
      ----t.java---
      import java.util.*;

      public class t {
          public static void main(String argv[]) {
              String key = null;
              Object[][] contents = new Object[][] {};
              try {
                PrimitiveBundle bundle = new PrimitiveBundle(contents);
                Object result = bundle.handleGetObject(key);
                System.out.println( "failed");
              } catch(NullPointerException e) {
                System.out.println( "OK");
              }
          }
      }

      class PrimitiveBundle extends ListResourceBundle {
        Object[][] list;
        PrimitiveBundle(Object[][] list) {
          this.list = list;
          setParent(null);
        }
        protected Object[][] getContents() {
          return list;
        }
      }

      #java -version
      java version "1.4.0-beta_refresh"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-beta_refresh-b69)
      Java HotSpot(TM) Client VM (build 1.4.0-beta_refresh-b69, mixed mode)

      #java t
      failed

      ======================================================================

            nlindenbsunw Norbert Lindenberg (Inactive)
            avusunw Avu Avu (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: