前阵子windows设置环境变量的时候卡死了,强制结束系统进程,结果导致用户环境变量全丢了,当时也没在意,后来使用jconsole的时候,问题来了,打开就报NPE空指针异常,无法调出选择连接的那个面板。网上搜了一下,发现有人使用JPS的时候,也报一样的错:
Exception in thread "main" java.lang.NullPointerException at sun.jvmstat.perfdata.monitor.protocol.local.LocalVmManager.activeVms(LocalVmManager.java:148) at sun.jvmstat.perfdata.monitor.protocol.local.MonitoredHostProvider.activeVms(MonitoredHostProvider.java:150) at sun.tools.jps.Jps.main(Jps.java:62)
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException at sun.jvmstat.perfdata.monitor.protocol.local.LocalVmManager.activeVms(LocalVmManager.java:127) at sun.jvmstat.perfdata.monitor.protocol.local.MonitoredHostProvider.activeVms(MonitoredHostProvider.java:133) at sun.tools.jconsole.ConnectDialog$ManagedVmTableModel.getManagedVirtualMachines(ConnectDialog.java:528) at sun.tools.jconsole.ConnectDialog$ManagedVmTableModel.refresh(ConnectDialog.java:511) at sun.tools.jconsole.ConnectDialog$ManagedVmTableModel.<init>(ConnectDialog.java:502) at sun.tools.jconsole.ConnectDialog.<init>(ConnectDialog.java:139) at sun.tools.jconsole.JConsole.showConnectDialog(JConsole.java:571) at sun.tools.jconsole.JConsole.access$100(JConsole.java:34) at sun.tools.jconsole.JConsole$4.run(JConsole.java:702) at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209) at java.awt.EventQueue.dispatchEvent(EventQueue.java:461) at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:242) at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149) at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)
这个bug详情很有用,看了这个大概知道是由于临时文件夹的问题引起的,echo %TMP%,发现是有路径的,start %TMP%,提示没权限。于是用管理员身份运行jconsole,一切正常了。然后修改用户环境变量,指向有权限的文件夹:C:\Users\xxx\AppData\Local\Temp,然后jconsole和jps终于可以正常使用了。
看来这个bug在后来的某个版本又被谁改回去了,应该再去Oracle把这个bug reopen一下。
《解决 jps/jconsole NullPointerException 的问题》上有1条评论