JDK-6780502 : HotSpotDiagnosticMXBean.setVMOption() throws NPE
  • Type: Bug
  • Component: core-svc
  • Sub-Component: java.lang.management
  • Affected Version: 6u10
  • Priority: P3
  • Status: Resolved
  • Resolution: Cannot Reproduce
  • OS: linux
  • CPU: x86
  • Submitted: 2008-12-04
  • Updated: 2023-12-14
  • 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
Description
FULL PRODUCT VERSION :
java version "1.6.0_10"
Java(TM) SE Runtime Environment (build 1.6.0_10-b33)
Java HotSpot(TM) Server VM (build 11.0-b15, mixed mode)


ADDITIONAL OS VERSION INFORMATION :
Linux zadok.basis.com 2.6.22-15-rt #1 SMP PREEMPT RT Wed Oct 22 02:21:14 GMT 2008 i686 GNU/Linux


A DESCRIPTION OF THE PROBLEM :
Calling setVMOption() with "HeapDumpPath" throws a NPE.  The reason is that although sun.management.Flag.getFlag("HeapDumpPath") returns a non-null Flag, the instance method Flag.getValue() returns a null value.  The if/else if clauses check for instanceof on the value returned from Flag.getValue().  Since in this case the value is null, none of the tests match, and the final else attempts to throw an IllegalArgumentException.  Building the message for this final IAE throws a NPE when trying to call getClass() on the value returned from Flag.getValue(), since it's null.

Any other flags for which a default value is not set (where Flag.getValue() returns null) will fail in the same way.

This began failing in 6u10.




STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
You can use the attached program to reproduce the problem.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
  Program should terminate normally.
ACTUAL -
  Program terminates with NPE

ERROR MESSAGES/STACK TRACES THAT OCCUR :
Exception in thread "main" java.lang.NullPointerException
	at sun.management.HotSpotDiagnostic.setVMOption(HotSpotDiagnostic.java:93)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at com.sun.jmx.mbeanserver.ConvertingMethod.invokeWithOpenReturn(ConvertingMethod.java:167)
	at com.sun.jmx.mbeanserver.MXBeanIntrospector.invokeM2(MXBeanIntrospector.java:96)
	at com.sun.jmx.mbeanserver.MXBeanIntrospector.invokeM2(MXBeanIntrospector.java:33)
	at com.sun.jmx.mbeanserver.MBeanIntrospector.invokeM(MBeanIntrospector.java:208)
	at com.sun.jmx.mbeanserver.PerInterface.invoke(PerInterface.java:120)
	at com.sun.jmx.mbeanserver.MBeanSupport.invoke(MBeanSupport.java:262)
	at javax.management.StandardMBean.invoke(StandardMBean.java:391)
	at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:836)
	at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:761)
	at com.sun.jmx.mbeanserver.MXBeanProxy$InvokeHandler.invoke(MXBeanProxy.java:134)
	at com.sun.jmx.mbeanserver.MXBeanProxy.invoke(MXBeanProxy.java:148)
	at javax.management.MBeanServerInvocationHandler.invoke(MBeanServerInvocationHandler.java:248)
	at $Proxy0.setVMOption(Unknown Source)
	at scratch.SetVMOptionBug.main(SetVMOptionBug.java:20)

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.io.IOException;
import java.lang.management.ManagementFactory;

import javax.management.MBeanServer;

import com.sun.management.HotSpotDiagnosticMXBean;

public class SetVMOptionBug
{
    public static void main(String[] p_argv) throws IOException
    {
        MBeanServer server = ManagementFactory.getPlatformMBeanServer();
        String beanName = "com.sun.management:type=HotSpotDiagnostic";
        HotSpotDiagnosticMXBean bean =
            ManagementFactory.newPlatformMXBeanProxy(server,
                                                     beanName,
                                                     HotSpotDiagnosticMXBean.class);
        bean.setVMOption("HeapDumpPath", "/tmp");
    }
}

---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Specify -XX:HeapDumpPath= on commandline.

Release Regression From : 5.0u7
The above release value was the last known release where this 
bug was not reproducible. Since then there has been a regression.

Release Regression From : 6
The above release value was the last known release where this 
bug was not reproducible. Since then there has been a regression.

Release Regression From : 6u7
The above release value was the last known release where this 
bug was not reproducible. Since then there has been a regression.

Comments
Tested with JDK7(1.7.0_06) and JDK8(1.8.0-internal), no more NullPointerException. But yes it is reproduced with JDK6(1.6.0_45) Please free free to reopen the bug if need a fix for JDK6
10-09-2013