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

Program gets java.lang.NullPointerException, works with -classic mode

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P3 P3
    • None
    • 1.3.1
    • hotspot
    • x86
    • windows_nt

      Name: rmT116609 Date: 07/13/2001


      java version "1.3.1"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1-b24)
      Java HotSpot(TM) Client VM (build 1.3.1-b24, mixed mode)


      If I compile this program with no options, and run it with no
      options, it gets a NullPointerException. If I run it with
      -classic, it runs to completion. The latter behavior appears
      to be the correct one.

      $ d:/jdk1.3.1/bin/javac Bug.java
      $ d:/jdk1.3.1/bin/java -cp . Bug
      java.lang.NullPointerException
      at java.util.HashMap.get(HashMap.java:266)
      at Bug$ObjectSet.get(Bug.java:15)
      at Bug$ObjectSet.representation(Bug.java:28)
      at Bug$ObjectSet.write(Bug.java:42)
      at Bug.main(Bug.java:67)
      Exception in thread "main"

      import java.lang.reflect.*;
      import java.lang.*;
      import java.io.*;
      import java.util.*;

      public class Bug
      {
         private static class ObjectSet {

            private HashMap objectMap = new HashMap();
            private static int objectCount = 0;
            private LinkedList workList = new LinkedList();

            Integer get(Object o) {
               Integer ref = (Integer) objectMap.get(o);

               if (ref == null) {
                  ref = new Integer(++ objectCount);
                  objectMap.put(o, ref);
                  workList.add(o);
               }
               return ref;
            }

            void representation(Object o)
            {
               if (o != null) {
                  get(o);
               }
            }

            void write() throws Exception
            {
               while (! workList.isEmpty()) {
                  Object o = (Object) workList.removeFirst();
                  Class clazz = o.getClass();

                  if (clazz.isArray()) {
                     final int length = Array.getLength(o);
                     // For every member of the array...
                     for (int i = 0; i < length; i++) {
                        representation(Array.get(o, i));
                     }
                  } // end array
                  else {
                     while (clazz != null) {
                        Field fields [] = clazz.getDeclaredFields();

                        // For each field of this object...
                        for (int i = 0; i < fields.length; i++) {
                           Field f = fields[i];
                           f.setAccessible(true);
                           representation(f.get(o));
                        }
                        clazz = clazz.getSuperclass();
                     }
                  } // end non-array object
               } // end worklist loop
            } // end write
         } // end ObjectSet

         public static void main (String [] args) throws Exception
         {
            ObjectSet os = new ObjectSet();
            Exception e = new Exception("here");
            os.get(e);
            os.write();
         }
      }



      With JDK 1.4.0-beta:
      =========================

      C:\>java Bug
      #
      # HotSpot Virtual Machine Error, Internal Error
      # Please report this error at
      # http://java.sun.com/cgi-bin/bugreport.cgi
      #
      # Error ID: 43113F32554E54494D45110E4350500314
      #
      # Problematic Thread: prio=5 tid=0x00761990 nid=0xd5 runnable
      #



      C:>java -server Bug
      #
      # HotSpot Virtual Machine Error, Internal Error
      # Please report this error at
      # http://java.sun.com/cgi-bin/bugreport.cgi
      #
      # Error ID: 53484152454432554E54494D450E435050014C
      #
      # Problematic Thread: prio=5 tid=0x00761990 nid=0xa1 runnable
      #
      (Review ID: 127894)
      ======================================================================
      ###@###.### 11/3/04 00:32 GMT

            kbr Kenneth Russell (Inactive)
            rmandalasunw Ranjith Mandala (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: