Skip to content

Commit

Permalink
Fix #2680 and fix #2667: Swing errors are catched properly and withou…
Browse files Browse the repository at this point in the history
…t freezing
  • Loading branch information
tobiasdiez committed Mar 23, 2017
1 parent 7ada957 commit ee2afd9
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 16 deletions.
5 changes: 2 additions & 3 deletions src/main/java/org/jabref/JabRefException.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@

public class JabRefException extends Exception {

private String localizedMessage;

private static final Log LOGGER = LogFactory.getLog(JabRefException.class);
private String localizedMessage;

public JabRefException(String message) {
super(message);
Expand All @@ -34,7 +33,7 @@ public JabRefException(Throwable cause) {
@Override
public String getLocalizedMessage() {
if (localizedMessage == null) {
LOGGER.warn("No localized message exception message defined. Falling back to getMessage().");
LOGGER.debug("No localized message exception message defined. Falling back to getMessage().");
return getMessage();
} else {
return localizedMessage;
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/jabref/gui/logging/GuiAppender.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.io.Serializable;

import org.jabref.gui.util.DefaultTaskExecutor;
import org.jabref.logic.logging.LogMessages;

import org.apache.logging.log4j.core.Filter;
Expand Down Expand Up @@ -43,6 +44,6 @@ public static GuiAppender createAppender(@PluginAttribute("name") String name,
*/
@Override
public void append(LogEvent event) {
LogMessages.getInstance().add(event);
DefaultTaskExecutor.runInJavaFXThread(() -> LogMessages.getInstance().add(event));
}
}
27 changes: 15 additions & 12 deletions src/main/java/org/jabref/gui/util/DefaultTaskExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,21 @@ public class DefaultTaskExecutor implements TaskExecutor {

private static final Log LOGGER = LogFactory.getLog(DefaultTaskExecutor.class);

public static <V> V runInJavaFXThread(Callable<V> callable) {
FutureTask<V> task = new FutureTask<>(callable);
Platform.runLater(task);
try {
return task.get();
} catch (InterruptedException | ExecutionException e) {
LOGGER.error(e);
return null;
}
}

public static void runInJavaFXThread(Runnable runnable) {
Platform.runLater(runnable);
}

@Override
public <V> void execute(BackgroundTask<V> task) {
new Thread(getJavaFXTask(task)).start();
Expand Down Expand Up @@ -54,16 +69,4 @@ private Exception convertToException(Throwable throwable) {
return new Exception(throwable);
}
}

public static <V> V runInJavaFXThread(Callable<V> callable) {
FutureTask<V> task = new FutureTask<>(callable);
Platform.runLater(task);
try {
return task.get();
} catch (InterruptedException | ExecutionException e) {
LOGGER.error(e);
return null;
}
}

}

0 comments on commit ee2afd9

Please sign in to comment.