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

javax.management.MBeanAttributeInfo.hashCode throws NullPointerException

XMLWordPrintable

      FULL PRODUCT VERSION :
      java version "1.7.0_02"
      Java(TM) SE Runtime Environment (build 1.7.0_02-b13)
      Java HotSpot(TM) 64-Bit Server VM (build 22.0-b10, mixed mode)


      ADDITIONAL OS VERSION INFORMATION :
      Linux Frank.schruefer.lan 2.6.34.10-0.2-desktop #1 SMP PREEMPT 2011-07-20 18:48:56 +0200 x86_64 x86_64 x86_64 GNU/Linux

      A DESCRIPTION OF THE PROBLEM :
      While trying to get a hashcode from an object found via the reflection API the following expception is thrown:

      java.lang.NullPointerException: null
         at javax.management.MBeanAttributeInfo.hashCode(MBeanAttributeInfo.java:304)
         at javax.management.MBeanInfo.arrayHashCode(MBeanInfo.java:532)
         at javax.management.MBeanInfo.hashCode(MBeanInfo.java:518)
         at com.sfs.util.HashList.containsObject(HashList.java:37)
         at com.sfs.lang.Memory.getMemoryUsageDeep(Memory.java:63)
         [...SNIP...]
         at com.sfs.siteforum.server.Service.service(Service.java:355)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Get any integer returned.
      ACTUAL -
      Exception.

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      1250165441993-20120224110146964 TYPE: java.lang.NullPointerException
      1250165441993-20120224110146964 TEXT: null
      1250165441993-20120224110146964 JAVA: at javax.management.MBeanAttributeInfo.hashCode(MBeanAttributeInfo.java:304)
      1250165441993-20120224110146964 JAVA: at javax.management.MBeanInfo.arrayHashCode(MBeanInfo.java:532)
      1250165441993-20120224110146964 JAVA: at javax.management.MBeanInfo.hashCode(MBeanInfo.java:518)
      1250165441993-20120224110146964 JAVA: at com.sfs.util.HashList.containsObject(HashList.java:37)
      1250165441993-20120224110146964 JAVA: at com.sfs.lang.Memory.getMemoryUsageDeep(Memory.java:63)
      1250165441993-20120224110146964 JAVA: at com.sfs.lang.Memory.getMemoryUsageDeep(Memory.java:82)
      1250165441993-20120224110146964 JAVA: at com.sfs.lang.Memory.getMemoryUsageDeep(Memory.java:82)
      1250165441993-20120224110146964 JAVA: at com.sfs.lang.Memory.getMemoryUsageDeep(Memory.java:82)
      1250165441993-20120224110146964 JAVA: at com.sfs.lang.Memory.getMemoryUsageDeep(Memory.java:70)
      1250165441993-20120224110146964 JAVA: at com.sfs.lang.Memory.getMemoryUsageDeep(Memory.java:82)
      1250165441993-20120224110146964 JAVA: at com.sfs.lang.Memory.getMemoryUsageDeep(Memory.java:82)
      1250165441993-20120224110146964 JAVA: at com.sfs.lang.Memory.getMemoryUsageDeep(Memory.java:82)
      1250165441993-20120224110146964 JAVA: at com.sfs.lang.Memory.getMemoryUsageDeep(Memory.java:82)
      1250165441993-20120224110146964 JAVA: at com.sfs.lang.Memory.getMemoryUsageDeep(Memory.java:82)
      1250165441993-20120224110146964 JAVA: at com.sfs.lang.Memory.getMemoryUsageDeep(Memory.java:70)
      1250165441993-20120224110146964 JAVA: at com.sfs.lang.Memory.getMemoryUsageDeep(Memory.java:82)
      1250165441993-20120224110146964 JAVA: at com.sfs.lang.Memory.getMemoryUsageDeep(Memory.java:82)
      1250165441993-20120224110146964 JAVA: at com.sfs.lang.Memory.getMemoryUsageDeep(Memory.java:70)
      1250165441993-20120224110146964 JAVA: at com.sfs.lang.Memory.getMemoryUsageDeep(Memory.java:82)
      1250165441993-20120224110146964 JAVA: at com.sfs.lang.Memory.getMemoryUsageDeep(Memory.java:82)
      1250165441993-20120224110146964 JAVA: at com.sfs.lang.Memory.getMemoryUsageDeep(Memory.java:82)
      1250165441993-20120224110146964 JAVA: at com.sfs.lang.Memory.getMemoryUsageDeep(Memory.java:82)
      1250165441993-20120224110146964 JAVA: at com.sfs.lang.Memory.getMemoryUsageDeep(Memory.java:82)
      1250165441993-20120224110146964 JAVA: at com.sfs.lang.Memory.getMemoryUsageDeep(Memory.java:82)
      1250165441993-20120224110146964 JAVA: at com.sfs.lang.Memory.getMemoryUsageDeep(Memory.java:82)
      1250165441993-20120224110146964 JAVA: at com.sfs.lang.Memory.getMemoryUsageDeep(Memory.java:82)
      1250165441993-20120224110146964 JAVA: at com.sfs.lang.Memory.getMemoryUsageDeep(Memory.java:82)
      1250165441993-20120224110146964 JAVA: at com.sfs.lang.Memory.getMemoryUsageDeep(Memory.java:70)
      1250165441993-20120224110146964 JAVA: at com.sfs.lang.Memory.getMemoryUsageDeep(Memory.java:82)
      1250165441993-20120224110146964 JAVA: at com.sfs.lang.Memory.getMemoryUsageDeep(Memory.java:82)
      1250165441993-20120224110146964 JAVA: at com.sfs.lang.Memory.getMemoryUsageDeep(Memory.java:82)
      1250165441993-20120224110146964 JAVA: at com.sfs.lang.Memory.getMemoryUsageDeep(Memory.java:82)
      1250165441993-20120224110146964 JAVA: at com.sfs.lang.Memory.getMemoryUsageDeep(Memory.java:82)
      1250165441993-20120224110146964 JAVA: at com.sfs.lang.Memory.getMemoryUsageDeep(Memory.java:82)
      1250165441993-20120224110146964 JAVA: at com.sfs.lang.Memory.getMemoryUsageDeep(Memory.java:82)
      1250165441993-20120224110146964 JAVA: at com.sfs.lang.Memory.getMemoryUsageDeep(Memory.java:54)
      1250165441993-20120224110146964 JAVA: at com.sfs.lang.Memory.getMemoryUsage(Memory.java:42)
      1250165441993-20120224110146964 JAVA: at com.sfs.siteforum.server.script.functions.Data.invoke_getMemoryUsageOfConnection(Data.java:255)
      1250165441993-20120224110146964 JAVA: at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      1250165441993-20120224110146964 JAVA: at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      1250165441993-20120224110146964 JAVA: at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      1250165441993-20120224110146964 JAVA: at java.lang.reflect.Method.invoke(Method.java:601)
      1250165441993-20120224110146964 JAVA: at com.sfs.siteforum.server.script.FunctionContent.invokeImpl(FunctionContent.java:171)
      1250165441993-20120224110146964 JAVA: at com.sfs.siteforum.server.script.FunctionContent.invoke(FunctionContent.java:153)
      1250165441993-20120224110146964 JAVA: at com.sfs.siteforum.server.script.AbstractContent.execute(AbstractContent.java:239)
      1250165441993-20120224110146964 JAVA: at com.sfs.siteforum.server.tree.Connection.execute_work(Connection.java:515)
      1250165441993-20120224110146964 JAVA: at com.sfs.siteforum.server.tree.RootBranch.service_exec(RootBranch.java:294)
      1250165441993-20120224110146964 JAVA: at com.sfs.siteforum.server.tree.RootBranch.service(RootBranch.java:219)
      1250165441993-20120224110146964 JAVA: at com.sfs.siteforum.server.Service.service(Service.java:355)
      1250165441993-20120224110146964 JAVA: at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)


      REPRODUCIBILITY :
      This bug can be reproduced always.
      Steps to Reproduce (be specific):

      Testcase source code:

      -------------- SNIP --------------------
      import javax.management.*;

      public class Temp {

         public final static void main(String[] args) throws Exception {
            new MBeanAttributeInfo(null, null, null, true, true, false).hashCode();
            }

         }
      -------------- /SNIP --------------------



      java -classpath . Temp


      Expected: execute without exception

      Actual: Nullpointer exception:

      Exception in thread "main" java.lang.NullPointerException
              at javax.management.MBeanAttributeInfo.hashCode(MBeanAttributeInfo.java:304)
              at Temp.main(Temp.java:6)


      In this case there's just one line of sourcecode in the method and the
      checks for null are missing:

      -------- ACTUAL CODE (jdk1.7.0_02) ----------
          public int hashCode() {
              return getName().hashCode() ^ getType().hashCode();
      -------- /ACTUAL CODE -------------

      ------- SUGGESTED CODE ------------
          public int hashCode() {
              String n = getName();
              String t = getType();
              return (n == null ? 0 : n.hashCode()) ^ (t == null ? 0 : t.hashCode());
      ------- /SUGGESTED CODE -----------

            sjiang Shanliang Jiang (Inactive)
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: