Changeset 17392 in josm for trunk/src


Ignore:
Timestamp:
2020-12-07T10:58:03+01:00 (3 years ago)
Author:
GerdP
Message:

fix #19098: Unable to update plugin after crash of plugin

  • wait for completion of threads
  • don't start PluginHandler.updateOrdisablePluginAfterException(e) in EDT

tested with old buildings_tool.jar version 34113 which causes an immediate crash when a new data layer is created.
TODO: Why didn't any unit test find this obvious bug? Seems we are mocking too much?

Location:
trunk/src/org/openstreetmap/josm
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/bugreport/BugReportDialog.java

    r14176 r17392  
    230230            return SuppressionMode.NONE;
    231231        } else {
     232            PluginDownloadTask downloadTask = PluginHandler.updateOrdisablePluginAfterException(e);
    232233            return GuiHelper.runInEDTAndWaitAndReturn(() -> {
    233                 PluginDownloadTask downloadTask = PluginHandler.updateOrdisablePluginAfterException(e);
    234234                if (downloadTask != null) {
    235235                    // Ask for restart to install new plugin
  • trunk/src/org/openstreetmap/josm/plugins/PluginHandler.java

    r17390 r17392  
    3838import java.util.concurrent.CopyOnWriteArrayList;
    3939import java.util.concurrent.ExecutionException;
     40import java.util.concurrent.Future;
    4041import java.util.concurrent.FutureTask;
    4142import java.util.concurrent.TimeUnit;
     
    954955        }
    955956        try {
     957            Map<String, PluginInformation> ret = new HashMap<>();
    956958            ReadLocalPluginInformationTask task = new ReadLocalPluginInformationTask(monitor);
     959            Future<?> future = MainApplication.worker.submit(task);
    957960            try {
    958                 task.run();
    959             } catch (RuntimeException e) { // NOPMD
     961                future.get();
     962            } catch (ExecutionException e) {
    960963                Logging.error(e);
    961                 return null;
    962             }
    963             Map<String, PluginInformation> ret = new HashMap<>();
     964                return ret;
     965            } catch (InterruptedException e) {
     966                Logging.warn("InterruptedException in " + PluginHandler.class.getSimpleName()
     967                        + " while loading locally available plugin information");
     968                return ret;
     969            }
    964970            for (PluginInformation pi: task.getAvailablePlugins()) {
    965971                ret.put(pi.name, pi);
     
    11181124                    monitor.createSubTaskMonitor(1, false),
    11191125                    Preferences.main().getOnlinePluginSites(), displayErrMsg
    1120             );
    1121             task1.run();
    1122             List<PluginInformation> allPlugins = task1.getAvailablePlugins();
     1126                    );
     1127            List<PluginInformation> allPlugins = null;
     1128            Future<?> future = MainApplication.worker.submit(task1);
    11231129
    11241130            try {
     1131                future.get();
     1132                allPlugins = task1.getAvailablePlugins();
    11251133                plugins = buildListOfPluginsToLoad(parent, monitor.createSubTaskMonitor(1, false));
    11261134                // If only some plugins have to be updated, filter the list
     
    11291137                    plugins = SubclassFilteredCollection.filter(plugins, pi -> pluginsWantedName.contains(pi.name));
    11301138                }
    1131             } catch (RuntimeException e) { // NOPMD
    1132                 Logging.warn(tr("Failed to download plugin information list"));
     1139            } catch (ExecutionException e) {
     1140                Logging.warn(tr("Failed to download plugin information list") + ": ExecutionException");
    11331141                Logging.error(e);
     1142                // don't abort in case of error, continue with downloading plugins below
     1143            } catch (InterruptedException e) {
     1144                Logging.warn(tr("Failed to download plugin information list") + ": InterruptedException");
    11341145                // don't abort in case of error, continue with downloading plugins below
    11351146            }
     
    11701181                        pluginsToDownload,
    11711182                        tr("Update plugins")
    1172                 );
     1183                        );
     1184                future = MainApplication.worker.submit(pluginDownloadTask);
     1185
    11731186                try {
    1174                     pluginDownloadTask.run();
    1175                 } catch (RuntimeException e) { // NOPMD
     1187                    future.get();
     1188                } catch (ExecutionException e) {
    11761189                    Logging.error(e);
     1190                    alertFailedPluginUpdate(parent, pluginsToUpdate);
     1191                    return plugins;
     1192                } catch (InterruptedException e) {
     1193                    Logging.warn("InterruptedException in " + PluginHandler.class.getSimpleName()
     1194                            + " while updating plugins");
    11771195                    alertFailedPluginUpdate(parent, pluginsToUpdate);
    11781196                    return plugins;
Note: See TracChangeset for help on using the changeset viewer.