JDK-6925192 : REGRESSION:NullPointerException throws when bring up the FileChooser
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 6u19
  • Priority: P2
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_xp,windows_vista
  • CPU: x86
  • Submitted: 2010-02-10
  • Updated: 2011-01-19
  • Resolved: 2010-02-12
Related Reports
Duplicate :  
Relates :  
Description
J2SE Version (please include all output from java -version flag):

java version "1.6.0_19-ea"
Java(TM) SE Runtime Environment (build 1.6.0_19-ea-b01)
Java HotSpot(TM) Client VM (build 16.2-b01, mixed mode, sharing)

Does this problem occur on J2SE 1.4.x or 5.0.x ?  Yes / No (pick one)
No exception on 6.0 update 18


Operating System Configuration Information (be specific):
Windows Vista Business SP1

Hardware Configuration Information (be specific):
HP Pavillion dv9000
Windows Vista Business SP1 32 bit
3 GB RAM
Intel Core 2 Duo T9300



Bug Description:
11:45:54[00007:-4] dsi.client.module.DefaultExceptionHandler.uncaughtException(DefaultExceptionHandler.java:37)Uncaught exception in thread 7'Thread[Basic L&F File Loading Thread,6,main]'
---- 1 ---- Throwable - Class (class java.lang.NullPointerException) V(4.06.-01) ----
        ---- Message (null) ----
        at sun.awt.shell.Win32ShellFolder2.hasAttribute(Win32ShellFolder2.java:523)
        at sun.awt.shell.Win32ShellFolder2.isDirectory(Win32ShellFolder2.java:596)
        at javax.swing.filechooser.WindowsFileSystemView.isTraversable(FileSystemView.java:632)
        at javax.swing.JFileChooser.isTraversable(JFileChooser.java:1561)
        at javax.swing.plaf.basic.BasicDirectoryModel$LoadFilesThread.run0(BasicDirectoryModel.java:232)
        at javax.swing.plaf.basic.BasicDirectoryModel$LoadFilesThread.run(BasicDirectoryModel.java:211)



Steps to Reproduce (be specific):

Here is a code piece that I used to bring up the FileChooser. 


		JFileChooser fileDialog = null;
		fileDialog = new JFileChooser() {
			@Override
			public void approveSelection() {
				File file = getSelectedFile();
				if (file.exists() && file.isFile() && getDialogType() == JFileChooser.SAVE_DIALOG) {
					int answer = JOptionPane.showConfirmDialog(this, file + " exists. Overwrite?", "Overwrite?",
							JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
					if (answer != JOptionPane.OK_OPTION) {
						return;
					}
				}
				super.approveSelection();
			}
		};
		if (includeSearchAccessory)
			fileDialog.setAccessory(new ChooserSearchAccessory(fileDialog));
		fileDialog.setDialogType(type);
		fileDialog.setFileSelectionMode(mode);
		if (defaultDirectory != null)
			fileDialog.setCurrentDirectory(defaultDirectory);
		if (defaultFile != null)
			fileDialog.setSelectedFile(defaultFile);
		fileDialog.setMultiSelectionEnabled(false);
		if (filters != null) {
			for (int i = 0; i < filters.length; i++)
				fileDialog.addChoosableFileFilter(filters[i]);
		}

		if (includeAcceptAll)
			fileDialog.setFileFilter(fileDialog.getAcceptAllFileFilter());
		else
			fileDialog.removeChoosableFileFilter(fileDialog.getAcceptAllFileFilter());
		int value = JFileChooser.CANCEL_OPTION;
		if (type == JFileChooser.CUSTOM_DIALOG)
			value = fileDialog.showDialog(parent, approveButtonText);
		else if (type == JFileChooser.OPEN_DIALOG)
			value = fileDialog.showOpenDialog(parent);
		else if (type == JFileChooser.SAVE_DIALOG)
			value = fileDialog.showSaveDialog(parent);
Same problem reported by another CAP member:
-----------------------------------------------------------
With the Java version 1.6.0_19ea I receive the follow exception on the console. Because I have never see it on the previous version it is a regression. The problem occur on open the file chooser a second time and follows. The file that produce the exception are ever different. In the GUI there seems all ok. Only on the console this exception is to see.
 

Exception in thread "Basic L&F File Loading Thread" java.lang.NullPointerException

at sun.awt.shell.Win32ShellFolder2.hasAttribute(Unknown Source)

at sun.awt.shell.Win32ShellFolder2.isDirectory(Unknown Source)

at com.inet.report.config.datasource.swing.DataSourceEditor$11.accept(DataSourceEditor.java:756)

at javax.swing.JFileChooser.accept(Unknown Source)

at javax.swing.plaf.basic.BasicDirectoryModel$LoadFilesThread.run0(Unknown Source)

at javax.swing.plaf.basic.BasicDirectoryModel$LoadFilesThread.run(Unknown Source)


Our code is:

fileChooser.setFileFilter(new FileFilter(){

@Override

public boolean accept(File f) {

if( f.isDirectory() ){

 return true;

}

 if( f.getName().endsWith("xml") ){

 return true;

 }

return false;

 }

 @Override

 public String getDescription() {

 return "XML File";

 }

 });

 



Steps to Reproduce (be specific):

Comments
EVALUATION I can't reproduce the bug but I know the problem because of stacktrace of the exception from the bug description. There is a problem in hasAttribute method. The next code return invoke(new Callable<Boolean>() {... can throw NPE when the current thread is interrupted and the result of invoke() is NULL. This code should be changed to: Boolean result = invoke(new Callable<Boolean>() {... return result != null && result; JDK7 doesn't have such problem because it was fixed as a part of CR 6460525. May be in some cases this problem is reproduced often, but in common this is a rarely situation. The fix of the problem is simple and clear. The risk of the fix is LOW.
11-02-2010

EVALUATION may be related to 6923226
10-02-2010