Ticket #16010: v2-0024-ProgressMonitorExecutor-log-exceptions-raised-by-.patch

File v2-0024-ProgressMonitorExecutor-log-exceptions-raised-by-.patch, 2.1 KB (added by ris, 3 years ago)
  • src/org/openstreetmap/josm/gui/progress/swing/ProgressMonitorExecutor.java

    From 8e56a519c00f77da3053738946dedbb7801a9139 Mon Sep 17 00:00:00 2001
    From: Robert Scott <code@humanleg.org.uk>
    Date: Sat, 12 May 2018 11:23:23 +0100
    Subject: [PATCH v2 24/28] ProgressMonitorExecutor: log exceptions raised by
     runnables
    
    ---
     .../progress/swing/ProgressMonitorExecutor.java    | 23 ++++++++++++++++++++++
     1 file changed, 23 insertions(+)
    
    diff --git a/src/org/openstreetmap/josm/gui/progress/swing/ProgressMonitorExecutor.java b/src/org/openstreetmap/josm/gui/progress/swing/ProgressMonitorExecutor.java
    index 2a7f7de56..d046344f6 100644
    a b  
    11// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.gui.progress.swing;
    33
     4import java.util.concurrent.CancellationException;
     5import java.util.concurrent.ExecutionException;
     6import java.util.concurrent.Future;
    47import java.util.concurrent.LinkedBlockingQueue;
    58import java.util.concurrent.ThreadPoolExecutor;
    69import java.util.concurrent.TimeUnit;
    710
     11import org.openstreetmap.josm.tools.Logging;
    812import org.openstreetmap.josm.tools.Utils;
    913
    1014/**
    public class ProgressMonitorExecutor extends ThreadPoolExecutor { 
    3640        super.execute(command);
    3741    }
    3842
     43    @Override
     44    public void afterExecute(final Runnable r, Throwable t) {
     45        // largely as proposed by JDK8 docs
     46        super.afterExecute(r, t);
     47        if (t == null && r instanceof Future<?>) {
     48            try {
     49                Object result = ((Future<?>) r).get();
     50            } catch (CancellationException cancellationException) {
     51                t = cancellationException;
     52            } catch (ExecutionException executionException) {
     53                t = executionException.getCause();
     54            } catch (InterruptedException interruptedException) {
     55                Thread.currentThread().interrupt(); // ignore/reset
     56            }
     57        }
     58        if (t != null) {
     59            Logging.error("Thread {0} raised {1}", Thread.currentThread().getName(), t);
     60        }
     61    }
    3962}