提交 0710f8d3 编写于 作者: A andrew

8221246: NullPointerException within Win32ShellFolder2

Reviewed-by: andrew
Contributed-by: NAlex Kashchenko <akashche@redhat.com>
上级 20c17c10
/* /*
* Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -25,7 +25,8 @@ ...@@ -25,7 +25,8 @@
package sun.awt.shell; package sun.awt.shell;
import java.awt.*; import java.awt.Image;
import java.awt.Toolkit;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.io.File; import java.io.File;
...@@ -33,14 +34,29 @@ import java.io.FileNotFoundException; ...@@ -33,14 +34,29 @@ import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.security.AccessController; import java.security.AccessController;
import java.security.PrivilegedAction; import java.security.PrivilegedAction;
import java.util.*; import java.util.ArrayList;
import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.concurrent.*; import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.RejectedExecutionException;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.stream.Stream; import java.util.stream.Stream;
import static sun.awt.shell.Win32ShellFolder2.*;
import sun.awt.OSInfo; import sun.awt.OSInfo;
import sun.misc.ThreadGroupUtils; import sun.misc.ThreadGroupUtils;
import sun.util.logging.PlatformLogger;
import static sun.awt.shell.Win32ShellFolder2.DESKTOP;
import static sun.awt.shell.Win32ShellFolder2.DRIVES;
import static sun.awt.shell.Win32ShellFolder2.Invoker;
import static sun.awt.shell.Win32ShellFolder2.NETWORK;
import static sun.awt.shell.Win32ShellFolder2.PERSONAL;
import static sun.awt.shell.Win32ShellFolder2.RECENT;
// NOTE: This class supersedes Win32ShellFolderManager, which was removed // NOTE: This class supersedes Win32ShellFolderManager, which was removed
// from distribution after version 1.4.2. // from distribution after version 1.4.2.
...@@ -54,6 +70,9 @@ import sun.misc.ThreadGroupUtils; ...@@ -54,6 +70,9 @@ import sun.misc.ThreadGroupUtils;
public class Win32ShellFolderManager2 extends ShellFolderManager { public class Win32ShellFolderManager2 extends ShellFolderManager {
private static final PlatformLogger
log = PlatformLogger.getLogger("sun.awt.shell.Win32ShellFolderManager2");
static { static {
// Load library here // Load library here
sun.awt.windows.WToolkit.loadLibraries(); sun.awt.windows.WToolkit.loadLibraries();
...@@ -137,12 +156,13 @@ public class Win32ShellFolderManager2 extends ShellFolderManager { ...@@ -137,12 +156,13 @@ public class Win32ShellFolderManager2 extends ShellFolderManager {
if (desktop == null) { if (desktop == null) {
try { try {
desktop = new Win32ShellFolder2(DESKTOP); desktop = new Win32ShellFolder2(DESKTOP);
} catch (SecurityException e) { } catch (final SecurityException ignored) {
// Ignore error // Ignore, the message may have sensitive information, not
} catch (IOException e) { // accessible other ways
// Ignore error } catch (IOException | InterruptedException e) {
} catch (InterruptedException e) { if (log.isLoggable(PlatformLogger.Level.WARNING)) {
// Ignore error log.warning("Cannot access 'Desktop'", e);
}
} }
} }
return desktop; return desktop;
...@@ -152,12 +172,13 @@ public class Win32ShellFolderManager2 extends ShellFolderManager { ...@@ -152,12 +172,13 @@ public class Win32ShellFolderManager2 extends ShellFolderManager {
if (drives == null) { if (drives == null) {
try { try {
drives = new Win32ShellFolder2(DRIVES); drives = new Win32ShellFolder2(DRIVES);
} catch (SecurityException e) { } catch (final SecurityException ignored) {
// Ignore error // Ignore, the message may have sensitive information, not
} catch (IOException e) { // accessible other ways
// Ignore error } catch (IOException | InterruptedException e) {
} catch (InterruptedException e) { if (log.isLoggable(PlatformLogger.Level.WARNING)) {
// Ignore error log.warning("Cannot access 'Drives'", e);
}
} }
} }
return drives; return drives;
...@@ -170,12 +191,13 @@ public class Win32ShellFolderManager2 extends ShellFolderManager { ...@@ -170,12 +191,13 @@ public class Win32ShellFolderManager2 extends ShellFolderManager {
if (path != null) { if (path != null) {
recent = createShellFolder(getDesktop(), new File(path)); recent = createShellFolder(getDesktop(), new File(path));
} }
} catch (SecurityException e) { } catch (final SecurityException ignored) {
// Ignore error // Ignore, the message may have sensitive information, not
} catch (InterruptedException e) { // accessible other ways
// Ignore error } catch (InterruptedException | IOException e) {
} catch (IOException e) { if (log.isLoggable(PlatformLogger.Level.WARNING)) {
// Ignore error log.warning("Cannot access 'Recent'", e);
}
} }
} }
return recent; return recent;
...@@ -185,12 +207,13 @@ public class Win32ShellFolderManager2 extends ShellFolderManager { ...@@ -185,12 +207,13 @@ public class Win32ShellFolderManager2 extends ShellFolderManager {
if (network == null) { if (network == null) {
try { try {
network = new Win32ShellFolder2(NETWORK); network = new Win32ShellFolder2(NETWORK);
} catch (SecurityException e) { } catch (final SecurityException ignored) {
// Ignore error // Ignore, the message may have sensitive information, not
} catch (IOException e) { // accessible other ways
// Ignore error } catch (IOException | InterruptedException e) {
} catch (InterruptedException e) { if (log.isLoggable(PlatformLogger.Level.WARNING)) {
// Ignore error log.warning("Cannot access 'Network'", e);
}
} }
} }
return network; return network;
...@@ -210,12 +233,13 @@ public class Win32ShellFolderManager2 extends ShellFolderManager { ...@@ -210,12 +233,13 @@ public class Win32ShellFolderManager2 extends ShellFolderManager {
personal.setIsPersonal(); personal.setIsPersonal();
} }
} }
} catch (SecurityException e) { } catch (final SecurityException ignored) {
// Ignore error // Ignore, the message may have sensitive information, not
} catch (InterruptedException e) { // accessible other ways
// Ignore error } catch (InterruptedException | IOException e) {
} catch (IOException e) { if (log.isLoggable(PlatformLogger.Level.WARNING)) {
// Ignore error log.warning("Cannot access 'Personal'", e);
}
} }
} }
return personal; return personal;
...@@ -316,8 +340,14 @@ public class Win32ShellFolderManager2 extends ShellFolderManager { ...@@ -316,8 +340,14 @@ public class Win32ShellFolderManager2 extends ShellFolderManager {
folders.add(createShellFolder(new File((String)value))); folders.add(createShellFolder(new File((String)value)));
} }
} catch (IOException e) { } catch (IOException e) {
if (log.isLoggable(PlatformLogger.Level.WARNING)) {
log.warning("Cannot read value = " + value, e);
}
// Skip this value // Skip this value
} catch (InterruptedException e) { } catch (InterruptedException e) {
if (log.isLoggable(PlatformLogger.Level.WARNING)) {
log.warning("Cannot read value = " + value, e);
}
// Return empty result // Return empty result
return new File[0]; return new File[0];
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册