JDK-7148497 : javax.management.MBeanAttributeInfo.hashCode throws NullPointerException
  • Type: Bug
  • Component: core-svc
  • Sub-Component: java.lang.management
  • Affected Version: 7
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: linux
  • CPU: x86
  • Submitted: 2012-02-24
  • Updated: 2024-10-30
  • Resolved: 2013-09-10
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
tbdResolved
Related Reports
Duplicate :  
Description
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 -----------

Comments
will be fixed in 8023669
10-09-2013

EVALUATION The problem is not limited to the MBeanAttributeInfo.hashCode(), but is common to all javax.management.MBean*Info classes: MBeanAttributeInfo, MBeanConstructorInfo, MBeanFeatureInfo, MBeanInfo, MBeanNotificationInfo, MBeanOperationInfo and MBeanParameterInfo. The root cause of the problem is that these classes can be instantiated with some null fields (mainly, but not limited to, the name and type fields), and these fields are dereferenced unconditionnaly in some methods. Unconditionnal dereferencing is used in the hashCode method but also in the equals() method.
04-04-2012

PUBLIC COMMENTS Pending on a test case to reproduce the problem.
24-02-2012