Class BugReport
- java.lang.Object
-
- org.openstreetmap.josm.tools.bugreport.BugReport
-
- All Implemented Interfaces:
Serializable
public final class BugReport extends Object implements Serializable
This class contains utility methods to create and handle a bug report.It allows you to configure the format and request to send the bug report.
It also contains the main entry point for all components to use the bug report system: Call
intercept(Throwable)
to start handling an exception.Handling Exceptions
In your code, you should add try...catch blocks for any runtime exceptions that might happen. It is fine to catch throwable there.You should then add some debug information there. This can be the OSM ids that caused the error, information on the data you were working on or other local variables. Make sure that no exceptions may occur while computing the values. It is best to send plain local variables to put(...). If you need to do computations, put them into a lambda expression. Then simply throw the throwable you got from the bug report. The global exception handler will do the rest.
int id = ...; String tag = "..."; try { ... your code ... } catch (RuntimeException t) { throw BugReport.intercept(t).put("id", id).put("tag", () -> x.getTag()); }
Instead of re-throwing, you can callReportedException.warn()
. This will display a warning to the user and allow it to either report the exception or ignore it.- Since:
- 10285
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
BugReport.BugReportListener
A listener that listens to changes to this report.
-
Field Summary
Fields Modifier and Type Field Description private ReportedException
exception
private boolean
includeAllStackTraces
private boolean
includeData
private boolean
includeStatusReport
private CopyOnWriteArrayList<BugReport.BugReportListener>
listeners
private static long
serialVersionUID
-
Constructor Summary
Constructors Constructor Description BugReport(ReportedException e)
Create a new bug report
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addChangeListener(BugReport.BugReportListener listener)
Add a new change listener.private void
fireChange()
static String
getCallingMethod(int offset)
Find the method that called us.static StackTraceElement
getCallingMethod(int offset, String className, Predicate<String> methodName)
Find the method that called the given method on the current stack trace.String
getReportText(String header)
Gets the full string that should be send as error report.static ReportedException
intercept(Throwable t)
This should be called whenever you want to add more information to a given exception.boolean
isIncludeAllStackTraces()
Determines if this report should include the stack traces for all other threads.boolean
isIncludeData()
Determines if this report should include the data that was traced.boolean
isIncludeStatusReport()
Determines if this report should include a system status reportvoid
removeChangeListener(BugReport.BugReportListener listener)
Remove a change listener.void
setIncludeAllStackTraces(boolean includeAllStackTraces)
Sets if this report should include the stack traces for all other threads.void
setIncludeData(boolean includeData)
Set if this report should include the data that was traced.void
setIncludeStatusReport(boolean includeStatusReport)
Set if this report should include a system status report
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
includeStatusReport
private boolean includeStatusReport
-
includeData
private boolean includeData
-
includeAllStackTraces
private boolean includeAllStackTraces
-
exception
private final ReportedException exception
-
listeners
private final CopyOnWriteArrayList<BugReport.BugReportListener> listeners
-
-
Constructor Detail
-
BugReport
public BugReport(ReportedException e)
Create a new bug report- Parameters:
e
- TheReportedException
to use. No more data should be added after creating the report.
-
-
Method Detail
-
isIncludeStatusReport
public boolean isIncludeStatusReport()
Determines if this report should include a system status report- Returns:
true
to include it.- Since:
- 10597
-
setIncludeStatusReport
public void setIncludeStatusReport(boolean includeStatusReport)
Set if this report should include a system status report- Parameters:
includeStatusReport
- if the status report should be included- Since:
- 10585
-
isIncludeData
public boolean isIncludeData()
Determines if this report should include the data that was traced.- Returns:
true
to include it.- Since:
- 10597
-
setIncludeData
public void setIncludeData(boolean includeData)
Set if this report should include the data that was traced.- Parameters:
includeData
- if data should be included- Since:
- 10585
-
isIncludeAllStackTraces
public boolean isIncludeAllStackTraces()
Determines if this report should include the stack traces for all other threads.- Returns:
true
to include it.- Since:
- 10597
-
setIncludeAllStackTraces
public void setIncludeAllStackTraces(boolean includeAllStackTraces)
Sets if this report should include the stack traces for all other threads.- Parameters:
includeAllStackTraces
- if all stack traces should be included- Since:
- 10585
-
getReportText
public String getReportText(String header)
Gets the full string that should be send as error report.- Parameters:
header
- header text for the error report- Returns:
- The string.
- Since:
- 10585
-
addChangeListener
public void addChangeListener(BugReport.BugReportListener listener)
Add a new change listener.- Parameters:
listener
- The listener- Since:
- 10585
-
removeChangeListener
public void removeChangeListener(BugReport.BugReportListener listener)
Remove a change listener.- Parameters:
listener
- The listener- Since:
- 10585
-
fireChange
private void fireChange()
-
intercept
public static ReportedException intercept(Throwable t)
This should be called whenever you want to add more information to a given exception.- Parameters:
t
- The throwable that was thrown.- Returns:
- A
ReportedException
to which you can add additional information.
-
getCallingMethod
public static String getCallingMethod(int offset)
Find the method that called us.- Parameters:
offset
- How many methods to look back in the stack trace. 1 gives the method calling this method, 0 gives you getCallingMethod().- Returns:
- The method name.
-
getCallingMethod
public static StackTraceElement getCallingMethod(int offset, String className, Predicate<String> methodName)
Find the method that called the given method on the current stack trace.- Parameters:
offset
- How many methods to look back in the stack trace. 1 gives the method calling this method, 0 gives you the method with the given name..className
- The name of the class to search formethodName
- The name of the method to search for- Returns:
- The class and method name or null if it is unknown.
-
-