Changeset 10819 in josm for trunk/src/org/openstreetmap/josm/tools/bugreport/BugReportExceptionHandler.java
- Timestamp:
- 2016-08-15T23:33:32+02:00 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/tools/bugreport/BugReportExceptionHandler.java
r10649 r10819 1 1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.tools.bugreport; 3 4 import java.awt.GraphicsEnvironment;5 6 import javax.swing.JOptionPane;7 import javax.swing.SwingUtilities;8 9 import org.openstreetmap.josm.Main;10 import org.openstreetmap.josm.gui.preferences.plugin.PluginPreference;11 import org.openstreetmap.josm.plugins.PluginDownloadTask;12 import org.openstreetmap.josm.plugins.PluginHandler;13 3 14 4 /** … … 19 9 */ 20 10 public final class BugReportExceptionHandler implements Thread.UncaughtExceptionHandler { 21 22 private static boolean handlingInProgress;23 private static volatile BugReporterThread bugReporterThread;24 private static int exceptionCounter;25 private static boolean suppressExceptionDialogs;26 27 static final class BugReporterThread extends Thread {28 29 private final class BugReporterWorker implements Runnable {30 private final PluginDownloadTask pluginDownloadTask;31 32 private BugReporterWorker(PluginDownloadTask pluginDownloadTask) {33 this.pluginDownloadTask = pluginDownloadTask;34 }35 36 @Override37 public void run() {38 // Then ask for submitting a bug report, for exceptions thrown from a plugin too, unless updated to a new version39 if (pluginDownloadTask == null) {40 askForBugReport(e);41 } else {42 // Ask for restart to install new plugin43 PluginPreference.notifyDownloadResults(44 Main.parent, pluginDownloadTask, !pluginDownloadTask.getDownloadedPlugins().isEmpty());45 }46 }47 }48 49 private final Throwable e;50 51 /**52 * Constructs a new {@code BugReporterThread}.53 * @param t the exception54 */55 private BugReporterThread(Throwable t) {56 super("Bug Reporter");57 this.e = t;58 }59 60 static void askForBugReport(final Throwable e) {61 if (GraphicsEnvironment.isHeadless()) {62 return;63 }64 BugReport report = new BugReport(BugReport.intercept(e));65 BugReportDialog dialog = new BugReportDialog(report);66 dialog.setShowSuppress(exceptionCounter > 1);67 dialog.setVisible(true);68 suppressExceptionDialogs = dialog.shouldSuppressFurtherErrors();69 }70 71 @Override72 public void run() {73 // Give the user a chance to deactivate the plugin which threw the exception (if it was thrown from a plugin)74 SwingUtilities.invokeLater(new BugReporterWorker(PluginHandler.updateOrdisablePluginAfterException(e)));75 }76 }77 11 78 12 @Override … … 86 20 */ 87 21 public static synchronized void handleException(final Throwable e) { 88 if (handlingInProgress || suppressExceptionDialogs) 89 return; // we do not handle secondary exceptions, this gets too messy 90 if (bugReporterThread != null && bugReporterThread.isAlive()) 91 return; 92 handlingInProgress = true; 93 exceptionCounter++; 94 try { 95 Main.error(e); 96 if (Main.parent != null) { 97 if (e instanceof OutOfMemoryError) { 98 // do not translate the string, as translation may raise an exception 99 JOptionPane.showMessageDialog(Main.parent, "JOSM is out of memory. " + 100 "Strange things may happen.\nPlease restart JOSM with the -Xmx###M option,\n" + 101 "where ### is the number of MB assigned to JOSM (e.g. 256).\n" + 102 "Currently, " + Runtime.getRuntime().maxMemory()/1024/1024 + " MB are available to JOSM.", 103 "Error", 104 JOptionPane.ERROR_MESSAGE 105 ); 106 return; 107 } 108 109 bugReporterThread = new BugReporterThread(e); 110 bugReporterThread.start(); 111 } 112 } finally { 113 handlingInProgress = false; 114 } 22 BugReport.intercept(e).warn(); 115 23 } 116 24 … … 120 28 */ 121 29 public static boolean exceptionHandlingInProgress() { 122 return handlingInProgress;30 return BugReportQueue.getInstance().exceptionHandlingInProgress(); 123 31 } 124 32 }
Note:
See TracChangeset
for help on using the changeset viewer.
