diff -r d6b131d2bc8b -r edd69f959190 src/java.desktop/share/classes/java/awt/Desktop.java --- a/src/java.desktop/share/classes/java/awt/Desktop.java Thu Jan 18 13:55:26 2018 +0530 +++ b/src/java.desktop/share/classes/java/awt/Desktop.java Wed Jan 31 18:13:13 2018 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2017, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2018, 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 @@ -42,6 +42,9 @@ import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; +import java.net.URL; +import java.security.AccessController; +import java.security.PrivilegedAction; import java.util.Objects; import javax.swing.JMenuBar; @@ -363,15 +366,11 @@ * @throws NullPointerException if file is null * @throws IllegalArgumentException if file doesn't exist */ - private static void checkFileValidation(File file){ - if (file == null) throw new NullPointerException("File must not be null"); - + private static void checkFileValidation(File file) { if (!file.exists()) { throw new IllegalArgumentException("The file: " + file.getPath() + " doesn't exist."); } - - file.canRead(); } /** @@ -425,6 +424,7 @@ * @see java.awt.AWTPermission */ public void open(File file) throws IOException { + file = new File(file.getPath()); checkAWTPermission(); checkExec(); checkActionSupport(Action.OPEN); @@ -456,6 +456,7 @@ * @see java.awt.AWTPermission */ public void edit(File file) throws IOException { + file = new File(file.getPath()); checkAWTPermission(); checkExec(); checkActionSupport(Action.EDIT); @@ -486,6 +487,7 @@ * allowed to create a subprocess */ public void print(File file) throws IOException { + file = new File(file.getPath()); checkExec(); SecurityManager sm = System.getSecurityManager(); if (sm != null) { @@ -614,14 +616,6 @@ } } - private void checkDelete() throws SecurityException { - SecurityManager sm = System.getSecurityManager(); - if (sm != null) { - sm.checkPermission(new FilePermission("<>", - SecurityConstants.FILE_DELETE_ACTION)); - } - } - private void checkQuitPermission() { SecurityManager sm = System.getSecurityManager(); if (sm != null) { @@ -950,6 +944,8 @@ * @since 9 */ public void openHelpViewer() { + checkAWTPermission(); + checkExec(); checkEventsProcessingPermission(); checkActionSupport(Action.APP_HELP_VIEWER); peer.openHelpViewer(); @@ -995,9 +991,15 @@ * @since 9 */ public void browseFileDirectory(File file) { - checkRead(); + file = new File(file.getPath()); + checkAWTPermission(); + checkExec(); checkActionSupport(Action.BROWSE_FILE_DIR); checkFileValidation(file); + File parentFile = file.getParentFile(); + if (parentFile == null || !parentFile.exists()) { + throw new IllegalArgumentException("Parent folder doesn't exist"); + } peer.browseFileDirectory(file); } @@ -1017,10 +1019,18 @@ * * @since 9 */ - public boolean moveToTrash(final File file) { - checkDelete(); + public boolean moveToTrash(File file) { + file = new File(file.getPath()); + SecurityManager sm = System.getSecurityManager(); + if (sm != null) { + sm.checkDelete(file.getPath()); + } checkActionSupport(Action.MOVE_TO_TRASH); - checkFileValidation(file); + final File finalFile = file; + AccessController.doPrivileged((PrivilegedAction) () -> { + checkFileValidation(finalFile); + return null; + }); return peer.moveToTrash(file); } }