From 1e77cec677e789fbdcd1d16a1945509a95f499bd Mon Sep 17 00:00:00 2001 From: Jeremy Long Date: Tue, 23 Aug 2016 19:12:04 -0400 Subject: [PATCH] improved error reporting for issue #547 --- .../exception/ExceptionCollection.java | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/dependency-check-core/src/main/java/org/owasp/dependencycheck/exception/ExceptionCollection.java b/dependency-check-core/src/main/java/org/owasp/dependencycheck/exception/ExceptionCollection.java index cf0a1015f..94cae929d 100644 --- a/dependency-check-core/src/main/java/org/owasp/dependencycheck/exception/ExceptionCollection.java +++ b/dependency-check-core/src/main/java/org/owasp/dependencycheck/exception/ExceptionCollection.java @@ -90,7 +90,8 @@ public class ExceptionCollection extends Exception { this.exceptions.add(exceptions); this.fatal = fatal; } - /** + + /** * Instantiates a new exception collection. * * @param msg the exception message @@ -195,7 +196,7 @@ public class ExceptionCollection extends Exception { */ @Override public void printStackTrace(PrintStream s) { - s.println("Multiple Exceptions Occured"); + s.println("Multiple Exceptions Occurred"); super.printStackTrace(s); for (Throwable t : this.exceptions) { s.println("Next Exception:"); @@ -204,11 +205,23 @@ public class ExceptionCollection extends Exception { } /** - * Prints the stack trace to standard error. + * Returns the error message, including the message from all contained + * exceptions. + * + * @return the error message */ @Override - public void printStackTrace() { - this.printStackTrace(System.err); + public String getMessage() { + StringBuilder sb = new StringBuilder(); + final String msg = super.getMessage(); + if (msg == null || msg.isEmpty()) { + sb.append("One or more exceptions occured during analysis:"); + } else { + sb.append(msg); + } + for (Throwable t : this.exceptions) { + sb.append("\n\t").append(t.getMessage()); + } + return sb.toString(); } - }