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 {
|
| 48 | 48 | private final transient Thread caughtOnThread; |
| 49 | 49 | private String methodWarningFrom; |
| 50 | 50 | |
| 51 | | ReportedException(Throwable exception) { |
| | 51 | public ReportedException(Throwable exception) { |
| 52 | 52 | this(exception, Thread.currentThread()); |
| 53 | 53 | } |
| 54 | 54 | |
| 55 | | ReportedException(Throwable exception, Thread caughtOnThread) { |
| | 55 | public ReportedException(Throwable exception, Thread caughtOnThread) { |
| 56 | 56 | super(exception); |
| 57 | 57 | |
| 58 | 58 | try { |
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;
|
| 7 | 7 | import java.io.ByteArrayInputStream; |
| 8 | 8 | import java.io.File; |
| 9 | 9 | import java.io.IOException; |
| | 10 | import java.io.PrintWriter; |
| | 11 | import java.io.StringWriter; |
| 10 | 12 | import java.lang.annotation.Documented; |
| 11 | 13 | import java.lang.annotation.ElementType; |
| 12 | 14 | import java.lang.annotation.Retention; |
| … |
… |
import org.openstreetmap.josm.tools.Logging;
|
| 60 | 62 | import org.openstreetmap.josm.tools.MemoryManagerTest; |
| 61 | 63 | import org.openstreetmap.josm.tools.RightAndLefthandTraffic; |
| 62 | 64 | import org.openstreetmap.josm.tools.Territories; |
| | 65 | import org.openstreetmap.josm.tools.bugreport.ReportedException; |
| 63 | 66 | import org.openstreetmap.josm.tools.date.DateUtils; |
| 64 | 67 | |
| 65 | 68 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; |
| … |
… |
public class JOSMTestRules implements TestRule {
|
| 673 | 676 | if (exception != null) { |
| 674 | 677 | throw exception; |
| 675 | 678 | } 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 | } |
| 677 | 685 | throw new Exception(MessageFormat.format("Test timed out after {0}ms", timeout)); |
| 678 | 686 | } |
| 679 | 687 | } |