Ticket #16906: v1-0001-JOSMTestRules-use-ReportedException-with-now-publ.patch

File v1-0001-JOSMTestRules-use-ReportedException-with-now-publ.patch, 3.2 KB (added by ris, 4 months ago)
  • src/org/openstreetmap/josm/tools/bugreport/ReportedException.java

    From 0ae8b3e3b01b2fcaad06cd964af47436c127b5fd Mon Sep 17 00:00:00 2001
    From: Robert Scott <code@humanleg.org.uk>
    Date: Sat, 27 Oct 2018 14:51:49 +0100
    Subject: [PATCH v1 1/2] JOSMTestRules: use ReportedException (with now-public
     constructors) to format timeout stack traces properly
    
    ---
     .../openstreetmap/josm/tools/bugreport/ReportedException.java  |  4 ++--
     test/unit/org/openstreetmap/josm/testutils/JOSMTestRules.java  | 10 +++++++++-
     2 files changed, 11 insertions(+), 3 deletions(-)
    
    diff --git a/src/org/openstreetmap/josm/tools/bugreport/ReportedException.java b/src/org/openstreetmap/josm/tools/bugreport/ReportedException.java
    index cf990ac6f..0ca78e5f2 100644
    a b public class ReportedException extends RuntimeException { 
    4848    private final transient Thread caughtOnThread;
    4949    private String methodWarningFrom;
    5050
    51     ReportedException(Throwable exception) {
     51    public ReportedException(Throwable exception) {
    5252        this(exception, Thread.currentThread());
    5353    }
    5454
    55     ReportedException(Throwable exception, Thread caughtOnThread) {
     55    public ReportedException(Throwable exception, Thread caughtOnThread) {
    5656        super(exception);
    5757
    5858        try {
  • test/unit/org/openstreetmap/josm/testutils/JOSMTestRules.java

    diff --git a/test/unit/org/openstreetmap/josm/testutils/JOSMTestRules.java b/test/unit/org/openstreetmap/josm/testutils/JOSMTestRules.java
    index eed522f58..7d41bbd13 100644
    a b import java.awt.event.WindowEvent; 
    77import java.io.ByteArrayInputStream;
    88import java.io.File;
    99import java.io.IOException;
     10import java.io.PrintWriter;
     11import java.io.StringWriter;
    1012import java.lang.annotation.Documented;
    1113import java.lang.annotation.ElementType;
    1214import java.lang.annotation.Retention;
    import org.openstreetmap.josm.tools.Logging; 
    6062import org.openstreetmap.josm.tools.MemoryManagerTest;
    6163import org.openstreetmap.josm.tools.RightAndLefthandTraffic;
    6264import org.openstreetmap.josm.tools.Territories;
     65import org.openstreetmap.josm.tools.bugreport.ReportedException;
    6366import org.openstreetmap.josm.tools.date.DateUtils;
    6467
    6568import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
    public class JOSMTestRules implements TestRule { 
    673676                if (exception != null) {
    674677                    throw exception;
    675678                } else {
    676                     Logging.debug("Thread state at timeout: {0}", Thread.getAllStackTraces());
     679                    if (Logging.isLoggingEnabled(Logging.LEVEL_DEBUG)) {
     680                        // i.e. skip expensive formatting of stack trace if it won't be shown
     681                        final StringWriter sw = new StringWriter();
     682                        new ReportedException(exception).printReportThreadsTo(new PrintWriter(sw));
     683                        Logging.debug("Thread state at timeout: {0}", sw);
     684                    }
    677685                    throw new Exception(MessageFormat.format("Test timed out after {0}ms", timeout));
    678686                }
    679687            }