Skip to content

Commit

Permalink
[JENKINS-25734] - Prevent NPE in Executor/causeOfDeath page if the fi…
Browse files Browse the repository at this point in the history
…eld is null

The change does not fix the issue, but it suppresses NPE at least.
  • Loading branch information
oleg-nenashev committed Jun 7, 2015
1 parent 4f54c8a commit bf7f14b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
13 changes: 12 additions & 1 deletion core/src/main/java/hudson/Functions.java
Expand Up @@ -151,6 +151,7 @@
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;

Expand Down Expand Up @@ -1372,7 +1373,17 @@ public static <T> T defaulted(T value, T defaultValue) {
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
* &quot;No exception details&quot; 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();
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/hudson/model/Executor.java
Expand Up @@ -380,7 +380,7 @@ public boolean isParking() {
* @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;
}

Expand Down
4 changes: 3 additions & 1 deletion core/src/main/resources/hudson/Messages.properties
Expand Up @@ -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
ProxyConfiguration.Success=Success

Functions.NoExceptionDetails=No Exception details

0 comments on commit bf7f14b

Please sign in to comment.