/*
 * Copyright (c) 2024, 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
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 * or visit www.oracle.com if you need additional information or have any
 * questions.
 */

import javax.swing.*;

/**
 * This is a manual test to reproduce 'JFileChooser crashes with NullpointerException after JDK-8293862 in Windows'.
 * Steps to reproduce:
 * 1. Run the attached manual test(JFileChooserCrashTest.java) with Windows L&F.
 * eg: java -Dswing.defaultlaf=com.sun.java.swing.plaf.windows.WindowsLookAndFeel JFileChooserCrashTest.java
 * 2. When the FileChooser opens up, navigate to 'Downloads' and try to open it.
 * 3. It throws NullpointerException and the user will not be able to navigate to anything else and there is no workaround for this, need to close the application.
 * 4. This is reproducible only in Windows and specifically with Windows L&F.
 * 5. This is reproducible when the user tries to open certain system folders(with an image icon) like 'Downloads', 'Libraries' etc.
 */
public class JFileChooserCrashTest {

    public static void main(String[] args) throws Exception {
        SwingUtilities.invokeAndWait(() -> {
            JFileChooser fileChooser = new JFileChooser();
            JFrame frame = new JFrame("Test Downloads Icon");
            frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
            frame.setLocationRelativeTo(null);
            frame.setSize(500,500);
            frame.add(fileChooser);
            frame.setVisible(true);
        });
    }

}
