提交 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.
*
* This code is free software; you can redistribute it and/or modify it
......@@ -739,6 +739,11 @@ public class JFileChooser extends JComponent implements Accessible {
dialog.show();
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 = null;
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.
*
* This code is free software; you can redistribute it and/or modify it
......@@ -232,6 +232,10 @@ public class BasicDirectoryModel extends AbstractListModel implements PropertyCh
public void run0() {
FileSystemView fileSystem = filechooser.getFileSystemView();
if (isInterrupted()) {
return;
}
File[] list = fileSystem.getFiles(currentDirectory, filechooser.isFileHidingEnabled());
if (isInterrupted()) {
......@@ -268,8 +272,8 @@ public class BasicDirectoryModel extends AbstractListModel implements PropertyCh
// To avoid loads of synchronizations with Invoker and improve performance we
// execute the whole block on the COM thread
DoChangeContents doChangeContents = ShellFolder.getInvoker().invoke(new Callable<DoChangeContents>() {
public DoChangeContents call() throws Exception {
DoChangeContents doChangeContents = ShellFolder.invoke(new Callable<DoChangeContents>() {
public DoChangeContents call() {
int newSize = newFileCache.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.
*
* This code is free software; you can redistribute it and/or modify it
......@@ -289,8 +289,8 @@ public abstract class ShellFolder extends File {
// To avoid loads of synchronizations with Invoker and improve performance we
// synchronize the whole code of the sort method once
getInvoker().invoke(new Callable<Void>() {
public Void call() throws Exception {
invoke(new Callable<Void>() {
public Void call() {
// Check that we can use the ShellFolder.sortChildren() method:
// 1. All files have the same non-null parent
// 2. All files is ShellFolders
......@@ -330,8 +330,8 @@ public abstract class ShellFolder extends File {
public void sortChildren(final List<? extends File> files) {
// To avoid loads of synchronizations with Invoker and improve performance we
// synchronize the whole code of the sort method once
getInvoker().invoke(new Callable<Void>() {
public Void call() throws Exception {
invoke(new Callable<Void>() {
public Void call() {
Collections.sort(files, FILE_COMPARATOR);
return null;
......@@ -501,18 +501,62 @@ public abstract class ShellFolder extends File {
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.
*/
public static interface Invoker {
/**
* Invokes a callable task. If the {@code task} throws a checked exception,
* it will be wrapped into a {@link RuntimeException}
* Invokes a callable task.
*
* @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
*/
<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.
*
* This code is free software; you can redistribute it and/or modify it
......@@ -108,12 +108,8 @@ class ShellFolderManager {
}
private static class DirectInvoker implements ShellFolder.Invoker {
public <T> T invoke(Callable<T> task) {
try {
return task.call();
} catch (Exception e) {
throw new RuntimeException(e);
}
public <T> T invoke(Callable<T> task) throws Exception {
return task.call();
}
}
}
/*
* 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.
*
* This code is free software; you can redistribute it and/or modify it
......@@ -905,8 +904,8 @@ public class FilePane extends JPanel implements PropertyChangeListener {
@Override
public void sort() {
ShellFolder.getInvoker().invoke(new Callable<Void>() {
public Void call() throws Exception {
ShellFolder.invoke(new Callable<Void>() {
public Void call() {
DetailsTableRowSorter.super.sort();
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.
*
* This code is free software; you can redistribute it and/or modify it
......@@ -58,10 +58,15 @@ public class Win32ShellFolderManager2 extends ShellFolderManager {
}
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;
try {
pIDL = parent.parseDisplayName(file.getCanonicalPath());
......@@ -77,7 +82,8 @@ public class Win32ShellFolderManager2 extends ShellFolderManager {
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
while (pIDL != 0) {
long curPIDL = Win32ShellFolder2.copyFirstPIDLEntry(pIDL);
......@@ -108,7 +114,9 @@ public class Win32ShellFolderManager2 extends ShellFolderManager {
try {
desktop = new Win32ShellFolder2(DESKTOP);
} catch (IOException e) {
desktop = null;
// Ignore error
} catch (InterruptedException e) {
// Ignore error
}
}
return desktop;
......@@ -119,7 +127,9 @@ public class Win32ShellFolderManager2 extends ShellFolderManager {
try {
drives = new Win32ShellFolder2(DRIVES);
} catch (IOException e) {
drives = null;
// Ignore error
} catch (InterruptedException e) {
// Ignore error
}
}
return drives;
......@@ -132,8 +142,10 @@ public class Win32ShellFolderManager2 extends ShellFolderManager {
if (path != null) {
recent = createShellFolder(getDesktop(), new File(path));
}
} catch (InterruptedException e) {
// Ignore error
} catch (IOException e) {
recent = null;
// Ignore error
}
}
return recent;
......@@ -144,7 +156,9 @@ public class Win32ShellFolderManager2 extends ShellFolderManager {
try {
network = new Win32ShellFolder2(NETWORK);
} catch (IOException e) {
network = null;
// Ignore error
} catch (InterruptedException e) {
// Ignore error
}
}
return network;
......@@ -164,8 +178,10 @@ public class Win32ShellFolderManager2 extends ShellFolderManager {
personal.setIsPersonal();
}
}
} catch (InterruptedException e) {
// Ignore error
} catch (IOException e) {
personal = null;
// Ignore error
}
}
return personal;
......@@ -267,6 +283,9 @@ public class Win32ShellFolderManager2 extends ShellFolderManager {
}
} catch (IOException e) {
// Skip this value
} catch (InterruptedException e) {
// Return empty result
return new File[0];
}
} while (value != null);
......@@ -476,33 +495,39 @@ public class Win32ShellFolderManager2 extends ShellFolderManager {
return comThread;
}
public <T> T invoke(Callable<T> task) {
try {
if (Thread.currentThread() == comThread) {
// if it's already called from the COM
// thread, we don't need to delegate the task
return task.call();
} else {
while (true) {
Future<T> future = submit(task);
try {
return future.get();
} 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;
public <T> T invoke(Callable<T> task) throws Exception {
if (Thread.currentThread() == comThread) {
// if it's already called from the COM
// thread, we don't need to delegate the task
return task.call();
} else {
Future<T> future;
try {
future = submit(task);
} catch (RejectedExecutionException e) {
throw new InterruptedException(e.getMessage());
}
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.
先完成此消息的编辑!
想要评论请 注册