On Fri, 17 Apr 2026 09:08:24 GMT, Michael McMahon <[email protected]> wrote:
>> Hi, >> >> This is a small fix for j.l.ProcessHandle on MacOS. Unlike other platforms, >> Mac returns a ProcessHandle for pid 0 whose descendants are _all_ processes >> on the system. This specific scenario tickles an off by one error where the >> descendants method tries to access an element past the end of the array of >> pids. The fix is to break from the loop before accessing this element. >> >> Thanks, >> >> Michael >> >> --------- >> - [x] I confirm that I make this contribution in accordance with the >> [OpenJDK Interim AI Policy](https://openjdk.org/legal/ai). > > Michael McMahon has updated the pull request incrementally with one > additional commit since the last revision: > > Update src/java.base/share/classes/java/lang/ProcessHandleImpl.java > > Co-authored-by: Andrey Turbanov <[email protected]> The purpose of the `do{...} while` loop is to sort the descendants to the beginning of the arrays. If the desired result for pid == 0 is to return all processes, then it should not be wasting time selecting and sorting. Just return a Stream of all of the ProcessHandles (or skip the sorting). ------------- PR Comment: https://git.openjdk.org/jdk/pull/30763#issuecomment-4274145124
