Ignore:
Timestamp:
2016-08-15T23:33:32+02:00 (10 years ago)
Author:
Don-vip
Message:

fix #13352 - new bug report queue (patch by michael2402) - gsoc-core

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/tools/bugreport/BugReportExceptionHandler.java

    r10649 r10819  
    11// License: GPL. For details, see LICENSE file.
    22package 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;
    133
    144/**
     
    199 */
    2010public 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             @Override
    37             public void run() {
    38                 // Then ask for submitting a bug report, for exceptions thrown from a plugin too, unless updated to a new version
    39                 if (pluginDownloadTask == null) {
    40                     askForBugReport(e);
    41                 } else {
    42                     // Ask for restart to install new plugin
    43                     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 exception
    54          */
    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         @Override
    72         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     }
    7711
    7812    @Override
     
    8620     */
    8721    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();
    11523    }
    11624
     
    12028     */
    12129    public static boolean exceptionHandlingInProgress() {
    122         return handlingInProgress;
     30        return BugReportQueue.getInstance().exceptionHandlingInProgress();
    12331    }
    12432}
Note: See TracChangeset for help on using the changeset viewer.