4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 import java.awt.Robot; 25 import java.awt.event.KeyEvent; 26 import java.io.File; 27 import java.io.IOException; 28 import java.io.InputStream; 29 import java.io.PrintWriter; 30 import java.util.concurrent.TimeUnit; 31 import javax.swing.JFileChooser; 32 import javax.swing.SwingUtilities; 33 import javax.swing.filechooser.FileSystemView; 34 import sun.awt.OSInfo; 35 36 /** 37 * @test 38 * @bug 8062561 39 * @summary File system view returns null default directory 40 * @run main/othervm bug8062561 GENERATE_POLICY 41 * @run main/othervm/policy=security.policy bug8062561 CHECK_DEFAULT_DIR run 42 */ 43 public class bug8062561 { 44 45 private static final String POLICY_FILE = "security2.policy"; 46 private static volatile boolean fileChooserIsShown = false; 47 48 public static void main(String[] args) throws Exception { 49 50 String test = args[0]; 51 52 switch (test) { 53 case "GENERATE_POLICY": 54 generatePolicyFile(); 55 break; 56 case "CHECK_DEFAULT_DIR": 57 checkDefaultDirectory(); 58 break; 59 case "CHECK_FILE_CHOOSER": 60 checkFileChooser(); 61 break; 62 default: 63 throw new RuntimeException("Wrong argument!"); 64 } 65 } 66 67 private static void checkDefaultDirectory() { 68 if (System.getSecurityManager() == null) { 69 throw new RuntimeException("Security manager is not set!"); 70 } 71 72 File defaultDirectory = FileSystemView.getFileSystemView(). 73 getDefaultDirectory(); 74 if (defaultDirectory != null) { 75 throw new RuntimeException("File system default directory is null!"); 76 } 77 } 78 private static volatile JFileChooser fileChooser; 79 80 private static void checkFileChooser() throws Exception { 81 if (System.getSecurityManager() == null) { 82 throw new RuntimeException("Security manager is not set!"); 83 } 84 85 Robot robot = new Robot(); 86 robot.setAutoDelay(50); 87 88 SwingUtilities.invokeLater(new Runnable() { 89 90 public void run() { 91 fileChooser = new JFileChooser(); 92 fileChooser.showOpenDialog(null); 93 fileChooserIsShown = true; 94 System.out.println("Start file chooser: " + fileChooserIsShown); 95 } | 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 import jdk.testlibrary.OSInfo; 25 import java.awt.Robot; 26 import java.awt.event.KeyEvent; 27 import java.io.File; 28 import java.io.IOException; 29 import java.io.InputStream; 30 import java.io.PrintWriter; 31 import java.util.concurrent.TimeUnit; 32 import javax.swing.JFileChooser; 33 import javax.swing.SwingUtilities; 34 import javax.swing.filechooser.FileSystemView; 35 36 /** 37 * @test 38 * @bug 8062561 39 * @summary File system view returns null default directory 40 * @library ../../../../lib/testlibrary 41 * @build jdk.testlibrary.OSInfo 42 * @run main/othervm bug8062561 GENERATE_POLICY 43 * @run main/othervm/policy=security.policy bug8062561 CHECK_DEFAULT_DIR run 44 */ 45 public class bug8062561 { 46 47 private static final String POLICY_FILE = "security2.policy"; 48 private static volatile boolean fileChooserIsShown = false; 49 50 public static void main(String[] args) throws Exception { 51 52 String test = args[0]; 53 54 switch (test) { 55 case "GENERATE_POLICY": 56 generatePolicyFile(); 57 break; 58 case "CHECK_DEFAULT_DIR": 59 checkDefaultDirectory(); 60 break; 61 case "CHECK_FILE_CHOOSER": 62 checkFileChooser(); 63 break; 64 default: 65 throw new RuntimeException("Wrong argument!"); 66 } 67 } 68 69 private static void checkDefaultDirectory() { 70 if (System.getSecurityManager() == null) { 71 throw new RuntimeException("Security manager is not set!"); 72 } 73 74 File defaultDirectory = FileSystemView.getFileSystemView(). 75 getDefaultDirectory(); 76 if (defaultDirectory != null) { 77 throw new RuntimeException("File system default directory must be null! (FilePermission has not been granted in our policy file)."); 78 } 79 } 80 private static volatile JFileChooser fileChooser; 81 82 private static void checkFileChooser() throws Exception { 83 if (System.getSecurityManager() == null) { 84 throw new RuntimeException("Security manager is not set!"); 85 } 86 87 Robot robot = new Robot(); 88 robot.setAutoDelay(50); 89 90 SwingUtilities.invokeLater(new Runnable() { 91 92 public void run() { 93 fileChooser = new JFileChooser(); 94 fileChooser.showOpenDialog(null); 95 fileChooserIsShown = true; 96 System.out.println("Start file chooser: " + fileChooserIsShown); 97 } |