RFR: 8344059: Remove doPrivileged calls from windows platform sources in the java.desktop module [v3]

Kevin Rushforth kcr at openjdk.org
Thu Nov 14 18:34:15 UTC 2024


On Thu, 14 Nov 2024 10:52:44 GMT, Prasanta Sadhukhan <psadhukhan at openjdk.org> wrote:

>> Since JEP 486 : Permanently Disable the Security Manager
>> [https://bugs.openjdk.org/browse/JDK-8338625] is now integrated, calls to java.security.AccessController.doPrivileged are obsolete and can be removed. 
>> 
>> This PR takes care of the windows-platform files in the java.desktop module to have them removed.
>
> Prasanta Sadhukhan has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Remove GetPropertyAction

Looks good except for one use of `GetPropertyAction` that you forgot to remove. I left a question and possible suggestion as well.

src/java.desktop/windows/classes/sun/awt/Win32FontManager.java line 48:

> 46: public final class Win32FontManager extends SunFontManager {
> 47: 
> 48:     private static TrueTypeFont eudcFont;

Minor: This can still be kept final by using a local variable (initialized to null) in the static block and assigning this field to that local variable once at the end of the block.

Alternatively, you can use a Supplier< TrueTypeFont()> lambda and make even fewer changes (it will be closer to the original). Something like this, which we did in a couple places in FX:


        private static final TrueTypeFont eudcFont =
            ((Supplier<TrueTypeFont>) () -> {
                String eudcFile = getEUDCFontFile();
                if (eudcFile != null) {
                    try {
                        /* Must use Java rasteriser since GDI doesn't
                         * enumerate (allow direct use) of EUDC fonts.
                         */
                        return new TrueTypeFont(eudcFile, null, 0,
                                                    true, false);
                    } catch (FontFormatException e) {
                    }
                }
                return null;
            }).get();

src/java.desktop/windows/classes/sun/awt/windows/WFramePeer.java line 84:

> 82:     private static final boolean keepOnMinimize = "true".equals(
> 83:             new GetPropertyAction(
> 84:             "sun.awt.keepWorkingSetOnMinimize"));

Shouldn't this be changed to `System.getProperty`? `GetPropertyAction` implements `PrivilegedAction` and is deprecated for removal (so I'm surprised that this doesn't generate a fatal warning).

src/java.desktop/windows/classes/sun/print/PrintServiceLookupProvider.java line 95:

> 93: 
> 94:             // start the local printer listener thread
> 95:             AccessController.doPrivileged((PrivilegedAction<Thread>) () -> {

Can you remove the `@SuppressWarnings("removal")` from this method after this change?

-------------

PR Review: https://git.openjdk.org/jdk/pull/22083#pullrequestreview-2436854914
PR Review Comment: https://git.openjdk.org/jdk/pull/22083#discussion_r1842681934
PR Review Comment: https://git.openjdk.org/jdk/pull/22083#discussion_r1842709534
PR Review Comment: https://git.openjdk.org/jdk/pull/22083#discussion_r1842716366


More information about the client-libs-dev mailing list