diff --git a/core/src/main/java/hudson/Functions.java b/core/src/main/java/hudson/Functions.java index f331d7f1cb..ade2acc002 100644 --- a/core/src/main/java/hudson/Functions.java +++ b/core/src/main/java/hudson/Functions.java @@ -151,6 +151,7 @@ import com.google.common.base.Predicate; import com.google.common.base.Predicates; import hudson.util.RunList; import java.util.concurrent.atomic.AtomicLong; +import javax.annotation.CheckForNull; import org.kohsuke.accmod.Restricted; import org.kohsuke.accmod.restrictions.NoExternalUse; @@ -1372,7 +1373,17 @@ public class Functions { return value!=null ? value : defaultValue; } - public static String printThrowable(Throwable t) { + /** + * Gets info about the specified {@link Throwable}. + * @param t Input {@link Throwable} + * @return If {@link Throwable} is not null, a summary info with the + * stacktrace will be returned. Otherwise, the method returns a default + * "No exception details" string. + */ + public static String printThrowable(@CheckForNull Throwable t) { + if (t == null) { + return Messages.Functions_NoExceptionDetails(); + } StringWriter sw = new StringWriter(); t.printStackTrace(new PrintWriter(sw)); return sw.toString(); diff --git a/core/src/main/java/hudson/model/Executor.java b/core/src/main/java/hudson/model/Executor.java index 974b371495..bd125806ea 100644 --- a/core/src/main/java/hudson/model/Executor.java +++ b/core/src/main/java/hudson/model/Executor.java @@ -380,7 +380,7 @@ public class Executor extends Thread implements ModelObject { * @return null if the death is expected death or the thread is {@link #isAlive() still alive}. * @since 1.142 */ - public Throwable getCauseOfDeath() { + public @CheckForNull Throwable getCauseOfDeath() { return causeOfDeath; } diff --git a/core/src/main/resources/hudson/Messages.properties b/core/src/main/resources/hudson/Messages.properties index 2613298aff..00360f9b23 100644 --- a/core/src/main/resources/hudson/Messages.properties +++ b/core/src/main/resources/hudson/Messages.properties @@ -67,4 +67,6 @@ AboutJenkins.Description=See the version and license information. ProxyConfiguration.TestUrlRequired=Test URL is required. ProxyConfiguration.FailedToConnectViaProxy=Failed to connect to {0}. ProxyConfiguration.FailedToConnect=Failed to connect to {0} (code {1}). -ProxyConfiguration.Success=Success \ No newline at end of file +ProxyConfiguration.Success=Success + +Functions.NoExceptionDetails=No Exception details \ No newline at end of file