bug6484091.java revision 2362:00cd9dc3c2b5
155714Skris/*
255714Skris * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
355714Skris * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
455714Skris *
555714Skris * This code is free software; you can redistribute it and/or modify it
655714Skris * under the terms of the GNU General Public License version 2 only, as
755714Skris * published by the Free Software Foundation.
855714Skris *
955714Skris * This code is distributed in the hope that it will be useful, but WITHOUT
1055714Skris * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1155714Skris * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
1255714Skris * version 2 for more details (a copy is included in the LICENSE file that
1355714Skris * accompanied this code).
1455714Skris *
1555714Skris * You should have received a copy of the GNU General Public License version
1655714Skris * 2 along with this work; if not, write to the Free Software Foundation,
1755714Skris * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1855714Skris *
1955714Skris * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2055714Skris * or visit www.oracle.com if you need additional information or have any
2155714Skris * questions.
2255714Skris */
2355714Skris
2455714Skris/* @test
2555714Skris * @bug 6484091
2655714Skris * @summary FileSystemView leaks directory info
2755714Skris * @author Pavel Porvatov
2855714Skris   @run main bug6484091
2955714Skris */
3055714Skris
3155714Skrisimport javax.swing.filechooser.FileSystemView;
3255714Skrisimport java.io.File;
3355714Skrisimport java.security.AccessControlException;
3455714Skris
3555714Skrispublic class bug6484091 {
3655714Skris    public static void main(String[] args) {
3755714Skris        File dir = FileSystemView.getFileSystemView().getDefaultDirectory();
3855714Skris
3955714Skris        printDirContent(dir);
4055714Skris
4155714Skris        System.setSecurityManager(new SecurityManager());
4255714Skris
4355714Skris        // The next test cases use 'dir' obtained without SecurityManager
4455714Skris
4555714Skris        try {
4655714Skris            printDirContent(dir);
4755714Skris
4855714Skris            throw new RuntimeException("Dir content was derived bypass SecurityManager");
4955714Skris        } catch (AccessControlException e) {
5055714Skris            // It's a successful situation
5155714Skris        }
5255714Skris    }
5355714Skris
5455714Skris    private static void printDirContent(File dir) {
5555714Skris        System.out.println("Files in " + dir.getAbsolutePath() + ":");
5655714Skris
5755714Skris        for (File file : dir.listFiles()) {
5855714Skris            System.out.println(file.getName());
5955714Skris        }
6055714Skris    }
6155714Skris}
6255714Skris