Skip to content

Conversation

@jstourac
Copy link
Contributor

Even though this change doesn't makes this project able to compile with
JDK9+ it at least adds a possibility to utilize its classes and methods
in some other projects with regards the work with PIDs running on JDK9+.

We are using a "hack" to call the method for PID retrieval by reflection
because it is only present in Java 9 and newer. That allows us to still
compile this code on older JDKs.

As a consequence the pid number changed from integer to long so we had
to change it everywhere. Dependent projects should update their usages
appropriately to long too, although since long -> integer is just about
the precision loss issue and I am not aware of any platform (from those
we use) that uses long instead of integer for their PIDs, it shouldn't
be a big issue.

This is slightly related to what is being prepared here #120.

@jstourac
Copy link
Contributor Author

Note that this is still WIP. More check and tests should come but I've decided to at least share this here so you can freely comment and raise your concerns.

@jstourac jstourac force-pushed the jdk17 branch 2 times, most recently from a8c625c to ac898e8 Compare February 1, 2022 11:50
@jstourac jstourac force-pushed the jdk17 branch 2 times, most recently from b76e296 to cd2ebf6 Compare May 12, 2022 09:24
@jstourac jstourac marked this pull request as ready for review May 12, 2022 09:24
try {
Field f = process.getClass().getDeclaredField("pid");
f.setAccessible(true);
processId = f.getInt(process);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this OK? I can see the implementation of windows-specific function was updated, but not this one.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, good point - I updated this to getLong too, since the field is Long in new JDKs implementations. Still this should not break with the JDK8 hopefully :)

pidAsStr = pidAsStr.trim()
pidAsStr = pidAsStr.replaceAll('"', '')
pid = Integer.valueOf(pidAsStr)
pid = Long.parseLong(pidAsStr)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason why you are using Long.parseLong() instead of Long.valueOf() ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hm, truth, I suppose that we should stick with what it was here before. Also, since we are supposed to return Long (function definition), we actually should rather use valueOf. Updated.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AdamKrajcik, I've updated also other occurrences of the parseLong back to valueOf where applicable.

@jstourac jstourac force-pushed the jdk17 branch 2 times, most recently from cdca5b7 to c6cbbc3 Compare May 16, 2022 14:57
@jstourac
Copy link
Contributor Author

@AdamKrajcik thank you for your review. I've fixed both places and also rebased against latest master branch.

@jstourac
Copy link
Contributor Author

jstourac commented Jun 1, 2022

Ready for another round.

Copy link
Collaborator

@AdamKrajcik AdamKrajcik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything looks fine by me.

@AdamKrajcik AdamKrajcik removed the request for review from mmadzin June 8, 2022 12:24
* TODO: properly implement it for Unix/Linux systems as pkill -P kills only processes with given parent PID, it doesn't go recursively killing from bottom to top
*/
static int killTree(Integer pid, winappname) {
static Long killTree(Long pid, winappname) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jstourac please can you verify the return type as looking at the code it could have remained an int, if I'm not mistaken.

Copy link
Contributor Author

@jstourac jstourac Jun 13, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@PaulLodge, you're right, thanks for the catch - I've just pushed the fix. I'll also start internal test jobs again, just to be sure

Even though this change doesn't makes this project able to compile with
JDK9+ it at least adds a possibility to utilize its classes and methods
in some other projects with regards the work with PIDs running on JDK9+.

We are using a "hack" to call the method for PID retrieval by reflection
because it is only present in Java 9 and newer. That allows us to still
compile this code on older JDKs.

As a consequence the pid number changed from integer to long so we had
to change it everywhere. Dependent projects should update their usages
appropriately to long too, although since long -> integer is just about
the precision loss issue and I am not aware of any platform (from those
we use) that uses long instead of integer for their PIDs, it shouldn't
be a big issue.
@PaulLodge PaulLodge merged commit 914cf29 into web-servers:master Jun 15, 2022
@jstourac jstourac deleted the jdk17 branch June 15, 2022 07:16
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

Successfully merging this pull request may close these issues.

3 participants