-
Notifications
You must be signed in to change notification settings - Fork 6.3k
8381567: ProcessHandle.descendants fails with ArrayIndexOutOfBoundException for process 0 #30763
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
base: master
Are you sure you want to change the base?
Changes from 4 commits
2c62796
c746c05
13b9507
69a4874
557922d
ce462da
5f978aa
f50fb96
3d447ab
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -458,7 +458,10 @@ public Stream<ProcessHandle> descendants() { | |
| next++; | ||
| } | ||
| } | ||
| ppid = pids[++count]; // pick up the next pid to scan for | ||
| if (++count >= size) { | ||
| break; | ||
| } | ||
| ppid = pids[count]; // pick up the next pid to scan for | ||
| ppStart = starttimes[count]; // and its start time | ||
| } while (count < next); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Have you tried
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
It has already dereferenced the invalid index at that point. It might be possible to restructure the loop by putting the assignment to ppid and ppStart at the top, but the initial value for ppid is not taken from the array, which is probably why that code is at the end of the loop. |
||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| /* | ||
| * Copyright (c) 2026, Oracle and/or its affiliates. All rights reserved. | ||
| * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
| * | ||
| * This code is free software; you can redistribute it and/or modify it | ||
| * under the terms of the GNU General Public License version 2 only, as | ||
| * published by the Free Software Foundation. | ||
| * | ||
| * This code is distributed in the hope that it will be useful, but WITHOUT | ||
| * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
| * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
| * version 2 for more details (a copy is included in the LICENSE file that | ||
| * accompanied this code). | ||
| * | ||
| * You should have received a copy of the GNU General Public License version | ||
| * 2 along with this work; if not, write to the Free Software Foundation, | ||
| * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
| * | ||
| * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | ||
| * or visit www.oracle.com if you need additional information or have any | ||
| * questions. | ||
| */ | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| /* | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this have a |
||
| * @test | ||
| * @summary ProcessHandle.descendants fails with AIOOE for process 0 | ||
| * @requires os.family == "mac" | ||
| * @library /test/lib | ||
| * @run junit PidZero | ||
| */ | ||
| public class PidZero { | ||
| /** | ||
| * Test of ProcessHandle.descendants for pid 0 | ||
| * Only Macos allows a ProcessHandle to be instantiated for pid 0 | ||
| * which includes all processes on the system, but the implementation | ||
| * throws ArrayIndexOutOfBoundException without this fix. | ||
| */ | ||
| @Test | ||
| public void test() { | ||
| int num = ProcessHandle.of(0).orElseThrow().descendants().toList().size(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this have any assertion? E.g.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can wrap the invocation in assertDoesNotThrow() |
||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do the check without incrementing and increment below.
It looks odd to bump the count even though it's not used.