ADDITIONAL SYSTEM INFORMATION :
Observed at least on Microsoft Windows 7 64-bit, and Microsoft Windows 10 64-bit, always with build 1.8.0_191. The problem does not occur with 1.8.0_181 or 1.8.0_171.
A DESCRIPTION OF THE PROBLEM :
On Microsoft Windows systems with b191, when a SecurityManager is defined, opening a JFileChooser in a folder with broken shortcuts causes system popup messages to appear: "The item <somefile> that this shortcut refers to has been changed or moved, so this shortcut will no longer work properly. Do you want to delete this shortcut?"
The problem occurs in sun.awt.shell.Win32ShellFolderManager2.checkFile(File file, SecurityManager sm). In revision http://hg.openjdk.java.net/jdk8u/jdk8u/jdk/rev/12e8aa264316 code was added to check link targets, which ends up calling Win32ShellFolder2.getLinkLocation(true). The call to getLinkLocation with resolve=true causes the popup messages.
REGRESSION : Last worked in version 8u181
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Create a file on Windows desktop. Use Windows menus to create a shortcut to that file, also on Windows desktop. Delete the first file, leaving the shortcut.
Run a Java program, where a security manager has been defined with System.setSecurityManager, and create an instance of JFileChooser.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
No popup messages.
ACTUAL -
A system popup message appears: "The item <somefile> that this shortcut refers to has been changed or moved, so this shortcut will no longer work properly. Do you want to delete this shortcut?"
---------- BEGIN SOURCE ----------
import java.io.*;
import javax.swing.JFileChooser;
/////////////////////////////////////
//
// NOTE:
// There must be a broken shortcut in the Windows desktop before running this program.
//
public class BrokenLinkBug {
public static void main(String[] args) throws Exception {
// Creates a temporary security policy
final File tempPolicyFile = File.createTempFile("broken-links-bug-", ".policy");
tempPolicyFile.deleteOnExit();
try (final PrintStream policyStream = new PrintStream(new FileOutputStream(tempPolicyFile))) {
policyStream.println("grant { permission java.security.AllPermission; };");
}
System.setProperty("java.security.policy", tempPolicyFile.getAbsolutePath());
// Trigger the problem
System.setSecurityManager(new SecurityManager());
JFileChooser chooser = new JFileChooser();
chooser.showDialog(null, "Open"); // not really needed
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
To circumvent the issue, define a security manager where checkRead throws SecurityException for broken shortcuts. In order to detect a broken shortcut, use a Win32ShellFolderManager32 to create an instance of Win32ShellFolder for the shortcut file, then invoke getLinkLocation(false) (via reflection as the method is not public) and confirm that the resulting target exists.
FREQUENCY : always