javasysmon
javasysmon copied to clipboard
NullPointerException in ProcessInfo.stringFormat
Got below exception when running on Linux:
$ uname -a
Linux lonsl1100576 2.6.32-573.12.1.el6.x86_64 #1 SMP Mon Nov 23 12:55:32 EST 2015 x86_64 x86_64 x86_64 GNU/Linux
$ /apps/java/64/jdk1.8.0_45/bin/java -cp "lib/javasysmon-0.3.5.jar" com.jezhumble.javasysmon.JavaSysMon
..skipped output...
Exception in thread "main" java.lang.NullPointerException
at com.jezhumble.javasysmon.ProcessInfo.stringFormat(ProcessInfo.java:184)
at com.jezhumble.javasysmon.ProcessInfo.stringFormat(ProcessInfo.java:179)
at com.jezhumble.javasysmon.ProcessInfo.toString(ProcessInfo.java:160)
at com.jezhumble.javasysmon.JavaSysMon.main(JavaSysMon.java:98)
One of the process entries in your system is causing the issue. The 3 strings passed to ProcessInfo from LinuxProcessInfoParser are command, name, and owner. If command was null, it would have had an exception in LinuxProcessInfoParser. I suspect it is either name or owner. Owner cannot be blank. In /proc/PID/status of the bad process, the 'Name:' field is blank.
One could argue that javasysmon shouldn't fail on blank 'name' but one could also argue processes shouldn't have blank process names either.
To fix javasysmon, getFirstMatch() in LinuxProcessInfoParser should return "" if matcher.group(1) is null.
I don't think that asking people to change their processes on the server because one of the libraries can't survive an empty name is a valid response here. It is simply not always possible in production environment shared my multiple teams. To me the fix looks trivial.