Skip to content
Permalink
Browse files
8240690: Race condition between EDT and BasicDirectoryModel.FilesLoad…
…er.run0()

Reviewed-by: psadhukhan
  • Loading branch information
mrserb committed Mar 25, 2020
1 parent 40e667c commit 3399842d7eabcd29031b7f721cd12c725d0e7565
Showing 5 changed files with 345 additions and 121 deletions.
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2002, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2002, 2020, 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
@@ -22,30 +22,83 @@
* or visit www.oracle.com if you need additional information or have any
* questions.
*/

package com.sun.java.swing.plaf.gtk;

import java.awt.*;
import java.awt.event.*;
import java.beans.*;
import java.awt.AWTKeyStroke;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.Insets;
import java.awt.KeyboardFocusManager;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.io.File;
import java.io.IOException;
import java.text.MessageFormat;
import java.util.*;

import javax.swing.*;
import javax.swing.border.*;
import javax.swing.filechooser.*;
import javax.swing.event.*;
import javax.swing.plaf.*;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashSet;
import java.util.Locale;
import java.util.Set;
import java.util.Vector;

import javax.accessibility.AccessibleContext;
import javax.swing.AbstractAction;
import javax.swing.AbstractListModel;
import javax.swing.Action;
import javax.swing.ActionMap;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.ComboBoxModel;
import javax.swing.DefaultListCellRenderer;
import javax.swing.DefaultListSelectionModel;
import javax.swing.Icon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JFileChooser;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JRootPane;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTextField;
import javax.swing.KeyStroke;
import javax.swing.ListSelectionModel;
import javax.swing.SwingUtilities;
import javax.swing.TransferHandler;
import javax.swing.UIManager;
import javax.swing.border.EmptyBorder;
import javax.swing.event.ListDataEvent;
import javax.swing.event.ListDataListener;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.filechooser.FileFilter;
import javax.swing.filechooser.FileSystemView;
import javax.swing.filechooser.FileView;
import javax.swing.plaf.ActionMapUIResource;
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.basic.BasicDirectoryModel;
import javax.swing.table.*;
import javax.accessibility.*;

import sun.swing.SwingUtilities2;
import javax.swing.table.JTableHeader;
import javax.swing.table.TableCellRenderer;

import sun.swing.plaf.synth.*;
import sun.swing.FilePane;
import sun.awt.shell.ShellFolder;
import sun.swing.FilePane;
import sun.swing.SwingUtilities2;
import sun.swing.plaf.synth.SynthFileChooserUI;

/**
* GTK FileChooserUI.
@@ -914,21 +967,18 @@ public Action getApproveSelectionAction() {
}

@SuppressWarnings("serial") // Superclass is not serializable across versions
private class GTKDirectoryModel extends BasicDirectoryModel {
FileSystemView fsv;
private Comparator<File> fileComparator = new Comparator<File>() {
public int compare(File o, File o1) {
return fsv.getSystemDisplayName(o).compareTo(fsv.getSystemDisplayName(o1));
}
};

public GTKDirectoryModel() {
private final class GTKDirectoryModel extends BasicDirectoryModel {
private GTKDirectoryModel() {
super(getFileChooser());
}

protected void sort(Vector<? extends File> v) {
fsv = getFileChooser().getFileSystemView();
Collections.sort(v, fileComparator);
FileSystemView fsv = getFileChooser().getFileSystemView();
if (fsv == null) {
super.sort(v);
} else {
v.sort(Comparator.comparing(fsv::getSystemDisplayName));
}
}
}

@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2020, 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
@@ -22,35 +22,48 @@
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package javax.swing;

import javax.swing.event.*;
import javax.swing.filechooser.*;
import javax.swing.filechooser.FileFilter;
import javax.swing.plaf.FileChooserUI;

import javax.accessibility.*;

import java.io.*;
package javax.swing;

import java.util.Vector;
import java.awt.AWTEvent;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Container;
import java.awt.BorderLayout;
import java.awt.Window;
import java.awt.Dialog;
import java.awt.EventQueue;
import java.awt.Frame;
import java.awt.GraphicsEnvironment;
import java.awt.HeadlessException;
import java.awt.EventQueue;
import java.awt.Toolkit;
import java.awt.event.*;
import java.beans.JavaBean;
import java.awt.Window;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.HierarchyEvent;
import java.awt.event.HierarchyListener;
import java.awt.event.InputEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.beans.BeanProperty;
import java.beans.PropertyChangeListener;
import java.beans.JavaBean;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.io.File;
import java.io.IOException;
import java.io.InvalidObjectException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.lang.ref.WeakReference;
import java.util.Vector;

import javax.accessibility.Accessible;
import javax.accessibility.AccessibleContext;
import javax.accessibility.AccessibleRole;
import javax.swing.event.EventListenerList;
import javax.swing.filechooser.FileFilter;
import javax.swing.filechooser.FileSystemView;
import javax.swing.filechooser.FileView;
import javax.swing.plaf.FileChooserUI;

/**
* <code>JFileChooser</code> provides a simple mechanism for the user to
@@ -1610,20 +1623,23 @@ public Icon getIcon(File f) {
public boolean isTraversable(File f) {
Boolean traversable = null;
if (f != null) {
if (getFileView() != null) {
traversable = getFileView().isTraversable(f);
FileView fileView = getFileView();
if (fileView != null) {
traversable = fileView.isTraversable(f);
}

FileView uiFileView = getUI().getFileView(this);

if (traversable == null && uiFileView != null) {
traversable = uiFileView.isTraversable(f);
FileChooserUI ui = getUI();
if (traversable == null && ui != null) {
FileView uiFileView = ui.getFileView(this);
if (uiFileView != null) {
traversable = uiFileView.isTraversable(f);
}
}
if (traversable == null) {
traversable = getFileSystemView().isTraversable(f);
FileSystemView fileSystemView = getFileSystemView();
if (traversable == null && fileSystemView != null) {
traversable = fileSystemView.isTraversable(f);
}
}
return (traversable != null && traversable.booleanValue());
return traversable != null && traversable;
}

/**
@@ -1633,11 +1649,8 @@ public boolean isTraversable(File f) {
* @see FileFilter#accept
*/
public boolean accept(File f) {
boolean shown = true;
if(f != null && fileFilter != null) {
shown = fileFilter.accept(f);
}
return shown;
FileFilter filter = fileFilter;
return f == null || filter == null || filter.accept(f);
}

/**

0 comments on commit 3399842

Please sign in to comment.