提交 f6d3feef 编写于 作者: R rupashka

6460525: javax/swing/JFileChooser/6396844/TwentyThousandTest.java times out

Reviewed-by: malenkov, peterz
上级 4c55daa3
/* /*
* Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved. * Copyright 1997-2009 Sun Microsystems, Inc. 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
...@@ -739,6 +739,11 @@ public class JFileChooser extends JComponent implements Accessible { ...@@ -739,6 +739,11 @@ public class JFileChooser extends JComponent implements Accessible {
dialog.show(); dialog.show();
firePropertyChange("JFileChooserDialogIsClosingProperty", dialog, null); firePropertyChange("JFileChooserDialogIsClosingProperty", dialog, null);
// Remove all components from dialog. The MetalFileChooserUI.installUI() method (and other LAFs)
// registers AWT listener for dialogs and produces memory leaks. It happens when
// installUI invoked after the showDialog method.
dialog.getContentPane().removeAll();
dialog.dispose(); dialog.dispose();
dialog = null; dialog = null;
return returnValue; return returnValue;
......
/* /*
* Copyright 1998-2008 Sun Microsystems, Inc. All Rights Reserved. * Copyright 1998-2009 Sun Microsystems, Inc. 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
...@@ -232,6 +232,10 @@ public class BasicDirectoryModel extends AbstractListModel implements PropertyCh ...@@ -232,6 +232,10 @@ public class BasicDirectoryModel extends AbstractListModel implements PropertyCh
public void run0() { public void run0() {
FileSystemView fileSystem = filechooser.getFileSystemView(); FileSystemView fileSystem = filechooser.getFileSystemView();
if (isInterrupted()) {
return;
}
File[] list = fileSystem.getFiles(currentDirectory, filechooser.isFileHidingEnabled()); File[] list = fileSystem.getFiles(currentDirectory, filechooser.isFileHidingEnabled());
if (isInterrupted()) { if (isInterrupted()) {
...@@ -268,8 +272,8 @@ public class BasicDirectoryModel extends AbstractListModel implements PropertyCh ...@@ -268,8 +272,8 @@ public class BasicDirectoryModel extends AbstractListModel implements PropertyCh
// To avoid loads of synchronizations with Invoker and improve performance we // To avoid loads of synchronizations with Invoker and improve performance we
// execute the whole block on the COM thread // execute the whole block on the COM thread
DoChangeContents doChangeContents = ShellFolder.getInvoker().invoke(new Callable<DoChangeContents>() { DoChangeContents doChangeContents = ShellFolder.invoke(new Callable<DoChangeContents>() {
public DoChangeContents call() throws Exception { public DoChangeContents call() {
int newSize = newFileCache.size(); int newSize = newFileCache.size();
int oldSize = fileCache.size(); int oldSize = fileCache.size();
......
/* /*
* Copyright 2000-2008 Sun Microsystems, Inc. All Rights Reserved. * Copyright 2000-2009 Sun Microsystems, Inc. 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
...@@ -289,8 +289,8 @@ public abstract class ShellFolder extends File { ...@@ -289,8 +289,8 @@ public abstract class ShellFolder extends File {
// To avoid loads of synchronizations with Invoker and improve performance we // To avoid loads of synchronizations with Invoker and improve performance we
// synchronize the whole code of the sort method once // synchronize the whole code of the sort method once
getInvoker().invoke(new Callable<Void>() { invoke(new Callable<Void>() {
public Void call() throws Exception { public Void call() {
// Check that we can use the ShellFolder.sortChildren() method: // Check that we can use the ShellFolder.sortChildren() method:
// 1. All files have the same non-null parent // 1. All files have the same non-null parent
// 2. All files is ShellFolders // 2. All files is ShellFolders
...@@ -330,8 +330,8 @@ public abstract class ShellFolder extends File { ...@@ -330,8 +330,8 @@ public abstract class ShellFolder extends File {
public void sortChildren(final List<? extends File> files) { public void sortChildren(final List<? extends File> files) {
// To avoid loads of synchronizations with Invoker and improve performance we // To avoid loads of synchronizations with Invoker and improve performance we
// synchronize the whole code of the sort method once // synchronize the whole code of the sort method once
getInvoker().invoke(new Callable<Void>() { invoke(new Callable<Void>() {
public Void call() throws Exception { public Void call() {
Collections.sort(files, FILE_COMPARATOR); Collections.sort(files, FILE_COMPARATOR);
return null; return null;
...@@ -501,18 +501,62 @@ public abstract class ShellFolder extends File { ...@@ -501,18 +501,62 @@ public abstract class ShellFolder extends File {
return invoker; return invoker;
} }
/**
* Invokes the {@code task} which doesn't throw checked exceptions
* from its {@code call} method. If invokation is interrupted then Thread.currentThread().isInterrupted() will
* be set and result will be {@code null}
*/
public static <T> T invoke(Callable<T> task) {
try {
return invoke(task, RuntimeException.class);
} catch (InterruptedException e) {
return null;
}
}
/**
* Invokes the {@code task} which throws checked exceptions from its {@code call} method.
* If invokation is interrupted then Thread.currentThread().isInterrupted() will
* be set and InterruptedException will be thrown as well.
*/
public static <T, E extends Throwable> T invoke(Callable<T> task, Class<E> exceptionClass)
throws InterruptedException, E {
try {
return getInvoker().invoke(task);
} catch (Exception e) {
if (e instanceof RuntimeException) {
// Rethrow unchecked exceptions
throw (RuntimeException) e;
}
if (e instanceof InterruptedException) {
// Set isInterrupted flag for current thread
Thread.currentThread().interrupt();
// Rethrow InterruptedException
throw (InterruptedException) e;
}
if (exceptionClass.isInstance(e)) {
throw exceptionClass.cast(e);
}
throw new RuntimeException("Unexpected error", e);
}
}
/** /**
* Interface allowing to invoke tasks in different environments on different platforms. * Interface allowing to invoke tasks in different environments on different platforms.
*/ */
public static interface Invoker { public static interface Invoker {
/** /**
* Invokes a callable task. If the {@code task} throws a checked exception, * Invokes a callable task.
* it will be wrapped into a {@link RuntimeException}
* *
* @param task a task to invoke * @param task a task to invoke
* @throws Exception {@code InterruptedException} or an exception that was thrown from the {@code task}
* @return the result of {@code task}'s invokation * @return the result of {@code task}'s invokation
*/ */
<T> T invoke(Callable<T> task); <T> T invoke(Callable<T> task) throws Exception;
} }
/** /**
......
/* /*
* Copyright 2000-2008 Sun Microsystems, Inc. All Rights Reserved. * Copyright 2000-2009 Sun Microsystems, Inc. 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
...@@ -108,12 +108,8 @@ class ShellFolderManager { ...@@ -108,12 +108,8 @@ class ShellFolderManager {
} }
private static class DirectInvoker implements ShellFolder.Invoker { private static class DirectInvoker implements ShellFolder.Invoker {
public <T> T invoke(Callable<T> task) { public <T> T invoke(Callable<T> task) throws Exception {
try { return task.call();
return task.call();
} catch (Exception e) {
throw new RuntimeException(e);
}
} }
} }
} }
/* /*
* Copyright 2003-2008 Sun Microsystems, Inc. All Rights Reserved. * Copyright 2003-2009 Sun Microsystems, Inc. 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
...@@ -905,8 +904,8 @@ public class FilePane extends JPanel implements PropertyChangeListener { ...@@ -905,8 +904,8 @@ public class FilePane extends JPanel implements PropertyChangeListener {
@Override @Override
public void sort() { public void sort() {
ShellFolder.getInvoker().invoke(new Callable<Void>() { ShellFolder.invoke(new Callable<Void>() {
public Void call() throws Exception { public Void call() {
DetailsTableRowSorter.super.sort(); DetailsTableRowSorter.super.sort();
return null; return null;
} }
......
/* /*
* Copyright 2003-2008 Sun Microsystems, Inc. All Rights Reserved. * Copyright 2003-2009 Sun Microsystems, Inc. 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
...@@ -58,10 +58,15 @@ public class Win32ShellFolderManager2 extends ShellFolderManager { ...@@ -58,10 +58,15 @@ public class Win32ShellFolderManager2 extends ShellFolderManager {
} }
public ShellFolder createShellFolder(File file) throws FileNotFoundException { public ShellFolder createShellFolder(File file) throws FileNotFoundException {
return createShellFolder(getDesktop(), file); try {
return createShellFolder(getDesktop(), file);
} catch (InterruptedException e) {
throw new FileNotFoundException("Execution was interrupted");
}
} }
static Win32ShellFolder2 createShellFolder(Win32ShellFolder2 parent, File file) throws FileNotFoundException { static Win32ShellFolder2 createShellFolder(Win32ShellFolder2 parent, File file)
throws FileNotFoundException, InterruptedException {
long pIDL; long pIDL;
try { try {
pIDL = parent.parseDisplayName(file.getCanonicalPath()); pIDL = parent.parseDisplayName(file.getCanonicalPath());
...@@ -77,7 +82,8 @@ public class Win32ShellFolderManager2 extends ShellFolderManager { ...@@ -77,7 +82,8 @@ public class Win32ShellFolderManager2 extends ShellFolderManager {
return folder; return folder;
} }
static Win32ShellFolder2 createShellFolderFromRelativePIDL(Win32ShellFolder2 parent, long pIDL) { static Win32ShellFolder2 createShellFolderFromRelativePIDL(Win32ShellFolder2 parent, long pIDL)
throws InterruptedException {
// Walk down this relative pIDL, creating new nodes for each of the entries // Walk down this relative pIDL, creating new nodes for each of the entries
while (pIDL != 0) { while (pIDL != 0) {
long curPIDL = Win32ShellFolder2.copyFirstPIDLEntry(pIDL); long curPIDL = Win32ShellFolder2.copyFirstPIDLEntry(pIDL);
...@@ -108,7 +114,9 @@ public class Win32ShellFolderManager2 extends ShellFolderManager { ...@@ -108,7 +114,9 @@ public class Win32ShellFolderManager2 extends ShellFolderManager {
try { try {
desktop = new Win32ShellFolder2(DESKTOP); desktop = new Win32ShellFolder2(DESKTOP);
} catch (IOException e) { } catch (IOException e) {
desktop = null; // Ignore error
} catch (InterruptedException e) {
// Ignore error
} }
} }
return desktop; return desktop;
...@@ -119,7 +127,9 @@ public class Win32ShellFolderManager2 extends ShellFolderManager { ...@@ -119,7 +127,9 @@ public class Win32ShellFolderManager2 extends ShellFolderManager {
try { try {
drives = new Win32ShellFolder2(DRIVES); drives = new Win32ShellFolder2(DRIVES);
} catch (IOException e) { } catch (IOException e) {
drives = null; // Ignore error
} catch (InterruptedException e) {
// Ignore error
} }
} }
return drives; return drives;
...@@ -132,8 +142,10 @@ public class Win32ShellFolderManager2 extends ShellFolderManager { ...@@ -132,8 +142,10 @@ public class Win32ShellFolderManager2 extends ShellFolderManager {
if (path != null) { if (path != null) {
recent = createShellFolder(getDesktop(), new File(path)); recent = createShellFolder(getDesktop(), new File(path));
} }
} catch (InterruptedException e) {
// Ignore error
} catch (IOException e) { } catch (IOException e) {
recent = null; // Ignore error
} }
} }
return recent; return recent;
...@@ -144,7 +156,9 @@ public class Win32ShellFolderManager2 extends ShellFolderManager { ...@@ -144,7 +156,9 @@ public class Win32ShellFolderManager2 extends ShellFolderManager {
try { try {
network = new Win32ShellFolder2(NETWORK); network = new Win32ShellFolder2(NETWORK);
} catch (IOException e) { } catch (IOException e) {
network = null; // Ignore error
} catch (InterruptedException e) {
// Ignore error
} }
} }
return network; return network;
...@@ -164,8 +178,10 @@ public class Win32ShellFolderManager2 extends ShellFolderManager { ...@@ -164,8 +178,10 @@ public class Win32ShellFolderManager2 extends ShellFolderManager {
personal.setIsPersonal(); personal.setIsPersonal();
} }
} }
} catch (InterruptedException e) {
// Ignore error
} catch (IOException e) { } catch (IOException e) {
personal = null; // Ignore error
} }
} }
return personal; return personal;
...@@ -267,6 +283,9 @@ public class Win32ShellFolderManager2 extends ShellFolderManager { ...@@ -267,6 +283,9 @@ public class Win32ShellFolderManager2 extends ShellFolderManager {
} }
} catch (IOException e) { } catch (IOException e) {
// Skip this value // Skip this value
} catch (InterruptedException e) {
// Return empty result
return new File[0];
} }
} while (value != null); } while (value != null);
...@@ -476,33 +495,39 @@ public class Win32ShellFolderManager2 extends ShellFolderManager { ...@@ -476,33 +495,39 @@ public class Win32ShellFolderManager2 extends ShellFolderManager {
return comThread; return comThread;
} }
public <T> T invoke(Callable<T> task) { public <T> T invoke(Callable<T> task) throws Exception {
try { if (Thread.currentThread() == comThread) {
if (Thread.currentThread() == comThread) { // if it's already called from the COM
// if it's already called from the COM // thread, we don't need to delegate the task
// thread, we don't need to delegate the task return task.call();
return task.call(); } else {
} else { Future<T> future;
while (true) {
Future<T> future = submit(task); try {
future = submit(task);
try { } catch (RejectedExecutionException e) {
return future.get(); throw new InterruptedException(e.getMessage());
} catch (InterruptedException e) {
// Repeat the attempt
future.cancel(true);
}
}
}
} catch (Exception e) {
Throwable cause = (e instanceof ExecutionException) ? e.getCause() : e;
if (cause instanceof RuntimeException) {
throw (RuntimeException) cause;
} }
if (cause instanceof Error) {
throw (Error) cause; try {
return future.get();
} catch (InterruptedException e) {
future.cancel(true);
throw e;
} catch (ExecutionException e) {
Throwable cause = e.getCause();
if (cause instanceof Exception) {
throw (Exception) cause;
}
if (cause instanceof Error) {
throw (Error) cause;
}
throw new RuntimeException("Unexpected error", cause);
} }
throw new RuntimeException(cause);
} }
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册