Changeset 18549 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2022-09-06T18:40:21+02:00 (2 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/progress/swing/ProgressMonitorExecutor.java
r18150 r18549 11 11 import org.openstreetmap.josm.tools.Logging; 12 12 import org.openstreetmap.josm.tools.Utils; 13 import org.openstreetmap.josm.tools.bugreport.BugReport; 13 14 14 15 /** … … 59 60 if (t != null) { 60 61 Logging.error("Thread {0} raised {1}", Thread.currentThread().getName(), t); 62 BugReport.addSuppressedException(t); 61 63 } 62 64 } -
trunk/src/org/openstreetmap/josm/gui/util/GuiHelper.java
r18365 r18549 212 212 static void handleEDTException(Throwable t) { 213 213 Logging.logWithStackTrace(Logging.LEVEL_ERROR, t, "Exception raised in EDT"); 214 BugReport.addSuppressedException(t); 214 215 } 215 216 -
trunk/src/org/openstreetmap/josm/tools/bugreport/BugReport.java
r15735 r18549 5 5 import java.io.Serializable; 6 6 import java.io.StringWriter; 7 import java.time.Instant; 8 import java.util.ArrayDeque; 9 import java.util.Deque; 7 10 import java.util.concurrent.CopyOnWriteArrayList; 8 11 import java.util.function.Predicate; 12 13 import org.openstreetmap.josm.tools.Pair; 9 14 10 15 /** … … 40 45 public final class BugReport implements Serializable { 41 46 private static final long serialVersionUID = 1L; 47 /** The maximum suppressed exceptions to keep to report */ 48 private static final byte MAXIMUM_SUPPRESSED_EXCEPTIONS = 4; 49 /** The list of suppressed exceptions, Pair<time reported, exception> */ 50 private static final Deque<Pair<Instant, Throwable>> SUPPRESSED_EXCEPTIONS = new ArrayDeque<>(MAXIMUM_SUPPRESSED_EXCEPTIONS); 42 51 43 52 private boolean includeStatusReport = true; … … 54 63 this.exception = e; 55 64 includeAllStackTraces = e.mayHaveConcurrentSource(); 65 } 66 67 /** 68 * Add a suppressed exception. Mostly useful for when a chain of exceptions causes an actual bug report. 69 * This should only be used when an exception is raised in {@link org.openstreetmap.josm.gui.util.GuiHelper} 70 * or {@link org.openstreetmap.josm.gui.progress.swing.ProgressMonitorExecutor} at this time. 71 * {@link org.openstreetmap.josm.tools.Logging} may call this in the future, when logging a throwable. 72 * @param t The throwable raised. If {@code null}, we add a new {@code NullPointerException} instead. 73 * @since 18549 74 */ 75 public static void addSuppressedException(Throwable t) { 76 SUPPRESSED_EXCEPTIONS.add(new Pair<>(Instant.now(), t != null ? t : new NullPointerException())); 77 // Ensure we don't call pop in more than MAXIMUM_SUPPRESSED_EXCEPTIONS threads. This guard is 78 // here just in case someone doesn't read the javadocs. 79 synchronized (SUPPRESSED_EXCEPTIONS) { 80 // Ensure we aren't keeping exceptions forever 81 while (SUPPRESSED_EXCEPTIONS.size() > MAXIMUM_SUPPRESSED_EXCEPTIONS) { 82 SUPPRESSED_EXCEPTIONS.pop(); 83 } 84 } 56 85 } 57 86 … … 136 165 exception.printReportThreadsTo(out); 137 166 } 167 synchronized (SUPPRESSED_EXCEPTIONS) { 168 if (!SUPPRESSED_EXCEPTIONS.isEmpty()) { 169 out.println("=== ADDITIONAL EXCEPTIONS ==="); 170 // Avoid multiple bug reports from reading from the deque at the same time. 171 while (SUPPRESSED_EXCEPTIONS.peek() != null) { 172 Pair<Instant, Throwable> currentException = SUPPRESSED_EXCEPTIONS.pop(); 173 out.println("==== Exception at " + currentException.a.toEpochMilli() + " ===="); 174 currentException.b.printStackTrace(out); 175 } 176 } 177 } 138 178 return stringWriter.toString().replaceAll("\r", ""); 139 179 }
Note:
See TracChangeset
for help on using the changeset viewer.