jdk/test/javax/swing/JFileChooser/6868611/bug6868611.java
author rupashka
Tue, 17 Nov 2009 16:01:09 +0300
changeset 4281 b4474a4716dd
child 5506 202f599c92aa
permissions -rw-r--r--
6868611: FileSystemView throws NullPointerException Reviewed-by: peterz
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4281
b4474a4716dd 6868611: FileSystemView throws NullPointerException
rupashka
parents:
diff changeset
     1
/*
b4474a4716dd 6868611: FileSystemView throws NullPointerException
rupashka
parents:
diff changeset
     2
 * Copyright 2009 Sun Microsystems, Inc.  All Rights Reserved.
b4474a4716dd 6868611: FileSystemView throws NullPointerException
rupashka
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
b4474a4716dd 6868611: FileSystemView throws NullPointerException
rupashka
parents:
diff changeset
     4
 *
b4474a4716dd 6868611: FileSystemView throws NullPointerException
rupashka
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
b4474a4716dd 6868611: FileSystemView throws NullPointerException
rupashka
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
b4474a4716dd 6868611: FileSystemView throws NullPointerException
rupashka
parents:
diff changeset
     7
 * published by the Free Software Foundation.
b4474a4716dd 6868611: FileSystemView throws NullPointerException
rupashka
parents:
diff changeset
     8
 *
b4474a4716dd 6868611: FileSystemView throws NullPointerException
rupashka
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
b4474a4716dd 6868611: FileSystemView throws NullPointerException
rupashka
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
b4474a4716dd 6868611: FileSystemView throws NullPointerException
rupashka
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
b4474a4716dd 6868611: FileSystemView throws NullPointerException
rupashka
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
b4474a4716dd 6868611: FileSystemView throws NullPointerException
rupashka
parents:
diff changeset
    13
 * accompanied this code).
b4474a4716dd 6868611: FileSystemView throws NullPointerException
rupashka
parents:
diff changeset
    14
 *
b4474a4716dd 6868611: FileSystemView throws NullPointerException
rupashka
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
b4474a4716dd 6868611: FileSystemView throws NullPointerException
rupashka
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
b4474a4716dd 6868611: FileSystemView throws NullPointerException
rupashka
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
b4474a4716dd 6868611: FileSystemView throws NullPointerException
rupashka
parents:
diff changeset
    18
 *
b4474a4716dd 6868611: FileSystemView throws NullPointerException
rupashka
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
b4474a4716dd 6868611: FileSystemView throws NullPointerException
rupashka
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
b4474a4716dd 6868611: FileSystemView throws NullPointerException
rupashka
parents:
diff changeset
    21
 * have any questions.
b4474a4716dd 6868611: FileSystemView throws NullPointerException
rupashka
parents:
diff changeset
    22
 */
b4474a4716dd 6868611: FileSystemView throws NullPointerException
rupashka
parents:
diff changeset
    23
b4474a4716dd 6868611: FileSystemView throws NullPointerException
rupashka
parents:
diff changeset
    24
/* @test
b4474a4716dd 6868611: FileSystemView throws NullPointerException
rupashka
parents:
diff changeset
    25
   @bug 6868611
b4474a4716dd 6868611: FileSystemView throws NullPointerException
rupashka
parents:
diff changeset
    26
   @summary FileSystemView throws NullPointerException
b4474a4716dd 6868611: FileSystemView throws NullPointerException
rupashka
parents:
diff changeset
    27
   @author Pavel Porvatov
b4474a4716dd 6868611: FileSystemView throws NullPointerException
rupashka
parents:
diff changeset
    28
   @run main bug6868611
b4474a4716dd 6868611: FileSystemView throws NullPointerException
rupashka
parents:
diff changeset
    29
*/
b4474a4716dd 6868611: FileSystemView throws NullPointerException
rupashka
parents:
diff changeset
    30
b4474a4716dd 6868611: FileSystemView throws NullPointerException
rupashka
parents:
diff changeset
    31
import javax.swing.*;
b4474a4716dd 6868611: FileSystemView throws NullPointerException
rupashka
parents:
diff changeset
    32
import javax.swing.filechooser.FileSystemView;
b4474a4716dd 6868611: FileSystemView throws NullPointerException
rupashka
parents:
diff changeset
    33
import java.io.File;
b4474a4716dd 6868611: FileSystemView throws NullPointerException
rupashka
parents:
diff changeset
    34
b4474a4716dd 6868611: FileSystemView throws NullPointerException
rupashka
parents:
diff changeset
    35
public class bug6868611 {
b4474a4716dd 6868611: FileSystemView throws NullPointerException
rupashka
parents:
diff changeset
    36
    private static final int COUNT = 1000;
b4474a4716dd 6868611: FileSystemView throws NullPointerException
rupashka
parents:
diff changeset
    37
b4474a4716dd 6868611: FileSystemView throws NullPointerException
rupashka
parents:
diff changeset
    38
    public static void main(String[] args) throws Exception {
b4474a4716dd 6868611: FileSystemView throws NullPointerException
rupashka
parents:
diff changeset
    39
        String tempDirProp = System.getProperty("java.io.tmpdir");
b4474a4716dd 6868611: FileSystemView throws NullPointerException
rupashka
parents:
diff changeset
    40
b4474a4716dd 6868611: FileSystemView throws NullPointerException
rupashka
parents:
diff changeset
    41
        final String tempDir = tempDirProp == null || !new File(tempDirProp).isDirectory() ?
b4474a4716dd 6868611: FileSystemView throws NullPointerException
rupashka
parents:
diff changeset
    42
            System.getProperty("user.home") : tempDirProp;
b4474a4716dd 6868611: FileSystemView throws NullPointerException
rupashka
parents:
diff changeset
    43
b4474a4716dd 6868611: FileSystemView throws NullPointerException
rupashka
parents:
diff changeset
    44
        System.out.println("Temp directory: " + tempDir);
b4474a4716dd 6868611: FileSystemView throws NullPointerException
rupashka
parents:
diff changeset
    45
b4474a4716dd 6868611: FileSystemView throws NullPointerException
rupashka
parents:
diff changeset
    46
        // Create 1000 files
b4474a4716dd 6868611: FileSystemView throws NullPointerException
rupashka
parents:
diff changeset
    47
        for (int i = 0; i < 1000; i++) {
b4474a4716dd 6868611: FileSystemView throws NullPointerException
rupashka
parents:
diff changeset
    48
            new File(tempDir, "temp" + i).createNewFile();
b4474a4716dd 6868611: FileSystemView throws NullPointerException
rupashka
parents:
diff changeset
    49
        }
b4474a4716dd 6868611: FileSystemView throws NullPointerException
rupashka
parents:
diff changeset
    50
b4474a4716dd 6868611: FileSystemView throws NullPointerException
rupashka
parents:
diff changeset
    51
        // Init default FileSystemView
b4474a4716dd 6868611: FileSystemView throws NullPointerException
rupashka
parents:
diff changeset
    52
        SwingUtilities.invokeAndWait(new Runnable() {
b4474a4716dd 6868611: FileSystemView throws NullPointerException
rupashka
parents:
diff changeset
    53
            public void run() {
b4474a4716dd 6868611: FileSystemView throws NullPointerException
rupashka
parents:
diff changeset
    54
                FileSystemView.getFileSystemView().getFiles(new File(tempDir), false);
b4474a4716dd 6868611: FileSystemView throws NullPointerException
rupashka
parents:
diff changeset
    55
            }
b4474a4716dd 6868611: FileSystemView throws NullPointerException
rupashka
parents:
diff changeset
    56
        });
b4474a4716dd 6868611: FileSystemView throws NullPointerException
rupashka
parents:
diff changeset
    57
b4474a4716dd 6868611: FileSystemView throws NullPointerException
rupashka
parents:
diff changeset
    58
        for (int i = 0; i < COUNT; i++) {
b4474a4716dd 6868611: FileSystemView throws NullPointerException
rupashka
parents:
diff changeset
    59
            Thread thread = new MyThread(tempDir);
b4474a4716dd 6868611: FileSystemView throws NullPointerException
rupashka
parents:
diff changeset
    60
b4474a4716dd 6868611: FileSystemView throws NullPointerException
rupashka
parents:
diff changeset
    61
            thread.start();
b4474a4716dd 6868611: FileSystemView throws NullPointerException
rupashka
parents:
diff changeset
    62
b4474a4716dd 6868611: FileSystemView throws NullPointerException
rupashka
parents:
diff changeset
    63
            Thread.sleep((long) (Math.random() * 100));
b4474a4716dd 6868611: FileSystemView throws NullPointerException
rupashka
parents:
diff changeset
    64
b4474a4716dd 6868611: FileSystemView throws NullPointerException
rupashka
parents:
diff changeset
    65
            thread.interrupt();
b4474a4716dd 6868611: FileSystemView throws NullPointerException
rupashka
parents:
diff changeset
    66
b4474a4716dd 6868611: FileSystemView throws NullPointerException
rupashka
parents:
diff changeset
    67
            if (i % 100 == 0) {
b4474a4716dd 6868611: FileSystemView throws NullPointerException
rupashka
parents:
diff changeset
    68
                System.out.print("*");
b4474a4716dd 6868611: FileSystemView throws NullPointerException
rupashka
parents:
diff changeset
    69
            }
b4474a4716dd 6868611: FileSystemView throws NullPointerException
rupashka
parents:
diff changeset
    70
        }
b4474a4716dd 6868611: FileSystemView throws NullPointerException
rupashka
parents:
diff changeset
    71
b4474a4716dd 6868611: FileSystemView throws NullPointerException
rupashka
parents:
diff changeset
    72
        System.out.println();
b4474a4716dd 6868611: FileSystemView throws NullPointerException
rupashka
parents:
diff changeset
    73
b4474a4716dd 6868611: FileSystemView throws NullPointerException
rupashka
parents:
diff changeset
    74
        // Remove 1000 files
b4474a4716dd 6868611: FileSystemView throws NullPointerException
rupashka
parents:
diff changeset
    75
        for (int i = 0; i < 1000; i++) {
b4474a4716dd 6868611: FileSystemView throws NullPointerException
rupashka
parents:
diff changeset
    76
            new File(tempDir, "temp" + i).delete();
b4474a4716dd 6868611: FileSystemView throws NullPointerException
rupashka
parents:
diff changeset
    77
        }
b4474a4716dd 6868611: FileSystemView throws NullPointerException
rupashka
parents:
diff changeset
    78
    }
b4474a4716dd 6868611: FileSystemView throws NullPointerException
rupashka
parents:
diff changeset
    79
b4474a4716dd 6868611: FileSystemView throws NullPointerException
rupashka
parents:
diff changeset
    80
    private static class MyThread extends Thread {
b4474a4716dd 6868611: FileSystemView throws NullPointerException
rupashka
parents:
diff changeset
    81
        private final String dir;
b4474a4716dd 6868611: FileSystemView throws NullPointerException
rupashka
parents:
diff changeset
    82
b4474a4716dd 6868611: FileSystemView throws NullPointerException
rupashka
parents:
diff changeset
    83
        private MyThread(String dir) {
b4474a4716dd 6868611: FileSystemView throws NullPointerException
rupashka
parents:
diff changeset
    84
            this.dir = dir;
b4474a4716dd 6868611: FileSystemView throws NullPointerException
rupashka
parents:
diff changeset
    85
        }
b4474a4716dd 6868611: FileSystemView throws NullPointerException
rupashka
parents:
diff changeset
    86
b4474a4716dd 6868611: FileSystemView throws NullPointerException
rupashka
parents:
diff changeset
    87
        public void run() {
b4474a4716dd 6868611: FileSystemView throws NullPointerException
rupashka
parents:
diff changeset
    88
            FileSystemView fileSystemView = FileSystemView.getFileSystemView();
b4474a4716dd 6868611: FileSystemView throws NullPointerException
rupashka
parents:
diff changeset
    89
b4474a4716dd 6868611: FileSystemView throws NullPointerException
rupashka
parents:
diff changeset
    90
            fileSystemView.getFiles(new File(dir), false);
b4474a4716dd 6868611: FileSystemView throws NullPointerException
rupashka
parents:
diff changeset
    91
        }
b4474a4716dd 6868611: FileSystemView throws NullPointerException
rupashka
parents:
diff changeset
    92
    }
b4474a4716dd 6868611: FileSystemView throws NullPointerException
rupashka
parents:
diff changeset
    93
}