On Mon, 28 Jun 2021 12:20:38 GMT, Daniel Fuchs <[email protected]> wrote:
>> This cast is only to tell the compiler which overloaded method to call, and
>> I don't think there will be a real cast at runtime. It might look a little
>> ugly but extracting it into a variable declaration/definition plus a new
>> `initStatic` method seems not worth doing, IMHO.
>
> Why not simply declare a local variable in the static initializer below?
>
>
> private static final long CURRENT_PID;
> private static final boolean ALLOW_ATTACH_SELF;
> static {
> PrivilegedAction<ProcessHandle> pa = ProcessHandle::current;
> @SuppressWarnings("removal")
> long pid = AccessController.doPrivileged(pa).pid();
> CURRENT_PID = pid;
> String s = VM.getSavedProperty("jdk.attach.allowAttachSelf");
> ALLOW_ATTACH_SELF = "".equals(s) || Boolean.parseBoolean(s);
> }
I've just pushed a commit with a different fix:
private static final long CURRENT_PID = pid();
@SuppressWarnings("removal")
private static long pid() {
PrivilegedAction<ProcessHandle> pa = () -> ProcessHandle.current();
return AccessController.doPrivileged(pa).pid();
}
-------------
PR: https://git.openjdk.java.net/jdk17/pull/152