Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NPE when try to kill linux process running JDK8 #27

Open
agliznetsov opened this issue Apr 11, 2014 · 5 comments
Open

NPE when try to kill linux process running JDK8 #27

agliznetsov opened this issue Apr 11, 2014 · 5 comments

Comments

@agliznetsov
Copy link

java.lang.RuntimeException: Could not kill process id 5267
at com.jezhumble.javasysmon.LinuxMonitor.killProcess(LinuxMonitor.java:156)
at com.jezhumble.javasysmon.JavaSysMon.killProcess(JavaSysMon.java:242)
...
Caused by: java.lang.NullPointerException
at com.jezhumble.javasysmon.LinuxMonitor.killProcess(LinuxMonitor.java:154)
... 7 more

@csemrau
Copy link

csemrau commented Jan 25, 2016

We just stumbled over this bug in version 0.3.3. Looking at the sources, I expect it can still be found in 0.3.5.
What should one do now?

@rich-coe
Copy link

What JVM are you running?
One way I see this to occur is that there isn't a declaration in the JVM for java.lang.UNIXProcess.destroyProcess(int) which javasysmon is trying to invoke.

@csemrau
Copy link

csemrau commented Jan 25, 2016

We are using the following:

/etc/alternatives/java_sdk_1.8.0/bin/java -version
openjdk version "1.8.0_65"
OpenJDK Runtime Environment (build 1.8.0_65-b17)
OpenJDK 64-Bit Server VM (build 25.65-b01, mixed mode)

I also suspect that that method does not exist in the runtime we are using. There is a javasysmon fork from atlassian, which seems to fix this issue, by executing a kill command instead. Will check that out soon.

@rich-coe
Copy link

I ran this simple groovy program on oracle jdk-1.8 and jre-1.8.0-openjdk and it fails like your report
on openjdk. The trick in the javasysmon code only works on oracle java.

def dmeth = null
def csig = new Class[1]
csig[0] = int.class

try {
    Class clazz = Class.forName("java.lang.UNIXProcess");
    dmeth = clazz.getDeclaredMethod("destroyProcess", csig)
    dmeth.setAccessible(true);
 } catch (Exception ex) {
     println "exception ${ex}"
     ex.printStackTrace()
 }

error message from openjdk

 exception java.lang.NoSuchMethodException: java.lang.UNIXProcess.destroyProcess(int)
 java.lang.NoSuchMethodException: java.lang.UNIXProcess.destroyProcess(int)
    at java.lang.Class.getDeclaredMethod(Class.java:2130)
    at java_lang_Class$getDeclaredMethod.call(Unknown Source)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:120)
    at dtest.run(dtest.groovy:8)
    [...]

@danielflower
Copy link

Java 8 has added Process.destroyForcibly() which does what the above code tries to do, but using a public API instead of trying to execute private methods. But, this library is supposed to support Java 1.4+, so maybe the fix is to try to first find a paramaterless method called destroyForcibly (still using reflection) and fall back to the above code for Java 7 and earlier?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants