[jdk17] RFR: 8269409: Post JEP 411 refactoring: core-libs with maximum covering > 10K [v2]
    Weijun Wang 
    weijun at openjdk.java.net
       
    Mon Jun 28 14:22:51 UTC 2021
    
    
  
On Mon, 28 Jun 2021 12:20:38 GMT, Daniel Fuchs <dfuchs at openjdk.org> 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
    
    
More information about the net-dev
mailing list