提交 ae2e7b82 编写于 作者: A alexsch

8055304: More boxing for DirectoryComboBoxModel

Reviewed-by: serb, prr, skoivu
上级 8ac893cf
...@@ -1067,16 +1067,9 @@ public class WindowsFileChooserUI extends BasicFileChooserUI { ...@@ -1067,16 +1067,9 @@ public class WindowsFileChooserUI extends BasicFileChooserUI {
directories.clear(); directories.clear();
File[] baseFolders; File[] baseFolders = (useShellFolder)
if (useShellFolder) { ? (File[]) ShellFolder.get("fileChooserComboBoxFolders")
baseFolders = AccessController.doPrivileged(new PrivilegedAction<File[]>() { : fsv.getRoots();
public File[] run() {
return (File[]) ShellFolder.get("fileChooserComboBoxFolders");
}
});
} else {
baseFolders = fsv.getRoots();
}
directories.addAll(Arrays.asList(baseFolders)); directories.addAll(Arrays.asList(baseFolders));
// Get the canonical (full) path. This has the side // Get the canonical (full) path. This has the side
......
...@@ -941,16 +941,9 @@ public class MetalFileChooserUI extends BasicFileChooserUI { ...@@ -941,16 +941,9 @@ public class MetalFileChooserUI extends BasicFileChooserUI {
directories.clear(); directories.clear();
File[] baseFolders; File[] baseFolders = (useShellFolder)
if (useShellFolder) { ? (File[]) ShellFolder.get("fileChooserComboBoxFolders")
baseFolders = AccessController.doPrivileged(new PrivilegedAction<File[]>() { : fsv.getRoots();
public File[] run() {
return (File[]) ShellFolder.get("fileChooserComboBoxFolders");
}
});
} else {
baseFolders = fsv.getRoots();
}
directories.addAll(Arrays.asList(baseFolders)); directories.addAll(Arrays.asList(baseFolders));
// Get the canonical (full) path. This has the side // Get the canonical (full) path. This has the side
......
...@@ -81,11 +81,7 @@ public class WindowsPlacesBar extends JToolBar ...@@ -81,11 +81,7 @@ public class WindowsPlacesBar extends JToolBar
setBackground(bgColor); setBackground(bgColor);
FileSystemView fsv = fc.getFileSystemView(); FileSystemView fsv = fc.getFileSystemView();
files = AccessController.doPrivileged(new PrivilegedAction<File[]>() { files = (File[]) ShellFolder.get("fileChooserShortcutPanelFolders");
public File[] run() {
return (File[]) ShellFolder.get("fileChooserShortcutPanelFolders");
}
});
buttons = new JToggleButton[files.length]; buttons = new JToggleButton[files.length];
buttonGroup = new ButtonGroup(); buttonGroup = new ButtonGroup();
......
...@@ -769,16 +769,9 @@ public class SynthFileChooserUIImpl extends SynthFileChooserUI { ...@@ -769,16 +769,9 @@ public class SynthFileChooserUIImpl extends SynthFileChooserUI {
fireIntervalRemoved(this, 0, oldSize); fireIntervalRemoved(this, 0, oldSize);
} }
File[] baseFolders; File[] baseFolders = (useShellFolder)
if (useShellFolder) { ? (File[]) ShellFolder.get("fileChooserComboBoxFolders")
baseFolders = AccessController.doPrivileged(new PrivilegedAction<File[]>() { : fsv.getRoots();
public File[] run() {
return (File[]) ShellFolder.get("fileChooserComboBoxFolders");
}
});
} else {
baseFolders = fsv.getRoots();
}
directories.addAll(Arrays.asList(baseFolders)); directories.addAll(Arrays.asList(baseFolders));
// Get the canonical (full) path. This has the side // Get the canonical (full) path. This has the side
......
...@@ -36,6 +36,7 @@ import java.security.PrivilegedAction; ...@@ -36,6 +36,7 @@ import java.security.PrivilegedAction;
import java.util.*; import java.util.*;
import java.util.List; import java.util.List;
import java.util.concurrent.*; import java.util.concurrent.*;
import java.util.stream.Stream;
import static sun.awt.shell.Win32ShellFolder2.*; import static sun.awt.shell.Win32ShellFolder2.*;
import sun.awt.OSInfo; import sun.awt.OSInfo;
...@@ -251,7 +252,7 @@ public class Win32ShellFolderManager2 extends ShellFolderManager { ...@@ -251,7 +252,7 @@ public class Win32ShellFolderManager2 extends ShellFolderManager {
if (file == null) { if (file == null) {
file = getDesktop(); file = getDesktop();
} }
return file; return checkFile(file);
} else if (key.equals("roots")) { } else if (key.equals("roots")) {
// Should be "History" and "Desktop" ? // Should be "History" and "Desktop" ?
if (roots == null) { if (roots == null) {
...@@ -262,11 +263,11 @@ public class Win32ShellFolderManager2 extends ShellFolderManager { ...@@ -262,11 +263,11 @@ public class Win32ShellFolderManager2 extends ShellFolderManager {
roots = (File[])super.get(key); roots = (File[])super.get(key);
} }
} }
return roots; return checkFiles(roots);
} else if (key.equals("fileChooserComboBoxFolders")) { } else if (key.equals("fileChooserComboBoxFolders")) {
Win32ShellFolder2 desktop = getDesktop(); Win32ShellFolder2 desktop = getDesktop();
if (desktop != null) { if (desktop != null && checkFile(desktop) != null) {
ArrayList<File> folders = new ArrayList<File>(); ArrayList<File> folders = new ArrayList<File>();
Win32ShellFolder2 drives = getDrives(); Win32ShellFolder2 drives = getDrives();
...@@ -295,7 +296,7 @@ public class Win32ShellFolderManager2 extends ShellFolderManager { ...@@ -295,7 +296,7 @@ public class Win32ShellFolderManager2 extends ShellFolderManager {
} }
} }
} }
return folders.toArray(new File[folders.size()]); return checkFiles(folders);
} else { } else {
return super.get(key); return super.get(key);
} }
...@@ -332,7 +333,7 @@ public class Win32ShellFolderManager2 extends ShellFolderManager { ...@@ -332,7 +333,7 @@ public class Win32ShellFolderManager2 extends ShellFolderManager {
} }
} }
} }
return folders.toArray(new File[folders.size()]); return checkFiles(folders);
} else if (key.startsWith("fileChooserIcon ")) { } else if (key.startsWith("fileChooserIcon ")) {
String name = key.substring(key.indexOf(" ") + 1); String name = key.substring(key.indexOf(" ") + 1);
...@@ -378,6 +379,41 @@ public class Win32ShellFolderManager2 extends ShellFolderManager { ...@@ -378,6 +379,41 @@ public class Win32ShellFolderManager2 extends ShellFolderManager {
return null; return null;
} }
private File checkFile(File file) {
SecurityManager sm = System.getSecurityManager();
return (sm == null || file == null) ? file : checkFile(file, sm);
}
private File checkFile(File file, SecurityManager sm) {
try {
sm.checkRead(file.getPath());
return file;
} catch (SecurityException se) {
return null;
}
}
private File[] checkFiles(File[] files) {
SecurityManager sm = System.getSecurityManager();
if (sm == null || files == null || files.length == 0) {
return files;
}
return checkFiles(Arrays.stream(files), sm);
}
private File[] checkFiles(List<File> files) {
SecurityManager sm = System.getSecurityManager();
if (sm == null || files.isEmpty()) {
return files.toArray(new File[files.size()]);
}
return checkFiles(files.stream(), sm);
}
private File[] checkFiles(Stream<File> filesStream, SecurityManager sm) {
return filesStream.filter((file) -> checkFile(file, sm) != null)
.toArray(File[]::new);
}
/** /**
* Does <code>dir</code> represent a "computer" such as a node on the network, or * Does <code>dir</code> represent a "computer" such as a node on the network, or
* "My Computer" on the desktop. * "My Computer" on the desktop.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册