You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
NullPointerException on WindowsHardwareAbstractionLayer.getProcessor #632
I have a NullPointerException when calling the following code on Windows Server 2016, using the latest release of oshi:
SystemInfo si = new SystemInfo();
OperatingSystem os = si.getOperatingSystem();
CentralProcessor processor = si.getHardware().getProcessor();
The stacktrace:
WARN oshi.util.platform.windows.PerfDataUtil - Failed to add PDH Counter : \System\Context Switches/sec, Error code: 0xC0000BB8
WARN oshi.hardware.platform.windows.WindowsCentralProcessor - Unable to enumerate performance counter instances for Processor.
Exception in thread "Thread-0" java.lang.NullPointerException
at oshi.util.platform.windows.PerfDataUtil.removeAllCounters(PerfDataUtil.java:227)
at oshi.hardware.platform.windows.WindowsCentralProcessor.initPdhCounters(WindowsCentralProcessor.java:246)
at oshi.hardware.platform.windows.WindowsCentralProcessor.(WindowsCentralProcessor.java:125)
at oshi.hardware.platform.windows.WindowsHardwareAbstractionLayer.getProcessor(WindowsHardwareAbstractionLayer:64)
oshi can't retrive PDH counters and try to fall back to Wmi. To do that, it calls PerfDataUtil.removeAllCounters(PROCESSOR) at WindowsCentralProcessor:246
The problematic lines:
In my case I think that the first call to PerfDataUtil.createCounter(PROCESSOR, ... failed: the PROCESSOR key was never added to the queryMap map and we end up calling null.getValue().
Yep, looks like I missed that. I recall finding a similar mistake elsewhere, so there were probably two similar bugs and I only caught one of them. Please submit a PR!
Activity
dbwiddis commentedon Sep 27, 2018
Yep, looks like I missed that. I recall finding a similar mistake elsewhere, so there were probably two similar bugs and I only caught one of them. Please submit a PR!
dbwiddis commentedon Sep 28, 2018
Fixed in #634