Skip to content
Permalink
Browse files

[JENKINS-49025] Extending JENKINS-34488 fix yet again; JENKINS-39346 …

…only considered causes, but other Throwable fields could also be unserializable.
  • Loading branch information...
jglick committed Jan 18, 2018
1 parent bbab928 commit a48460ebdf7d03bedd82bb9e3e9de41481d58a4a
@@ -31,6 +31,8 @@
import org.codehaus.groovy.control.MultipleCompilationErrorsException;
import org.jenkinsci.plugins.workflow.graph.AtomNode;
import javax.annotation.Nonnull;
import jenkins.model.Jenkins;
import org.apache.commons.io.output.NullOutputStream;

/**
* Attached to {@link AtomNode} that caused an error.
@@ -44,6 +46,13 @@
public ErrorAction(@Nonnull Throwable error) {
if (isUnserializableException(error)) {
error = new ProxyException(error);
} else if (error != null) {
try {
Jenkins.XSTREAM2.toXMLUTF8(error, new NullOutputStream());
} catch (Exception x) {
// Typically SecurityException from ClassFilter.
error = new ProxyException(error);
}
}
this.error = error;
}
@@ -56,15 +65,6 @@ private boolean isUnserializableException(@CheckForNull Throwable error) {
if (error == null) {
return false;
}
try {
// Some exceptions are refused to be serialized for security reasons.
// (E.g. PowerAssertionError thrown by "assert false")
// See also hudson.util.XStream2
ClassFilter.DEFAULT.check(error.getClass());
ClassFilter.DEFAULT.check(error.getClass().getName());
} catch (SecurityException x) {
return true;
}
if (error instanceof MultipleCompilationErrorsException || error instanceof MissingMethodException) {
return true;
}
@@ -46,6 +46,7 @@

import hudson.model.Result;
import hudson.remoting.ProxyException;
import org.codehaus.groovy.runtime.NullObject;

/**
* Tests for {@link ErrorAction}
@@ -132,4 +133,25 @@ public void unserializableForSecurityReason() throws Exception {
r.assertLogContains("java.lang.NullPointerException: oops", b);
}

@Issue("JENKINS-49025")
@Test public void nestedFieldUnserializable() throws Exception {
WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
p.setDefinition(new CpsFlowDefinition(
"catchError {\n" +
" throw new " + X.class.getCanonicalName() + "()\n" +
"}\n" +
"echo 'got to the end'", false));
WorkflowRun b = r.assertBuildStatus(Result.FAILURE, p.scheduleBuild2(0).get());
r.assertLogContains("got to the end", b);
r.assertLogContains(X.class.getName(), b);
List<ErrorAction> errorActionList = extractErrorActions(b.asFlowExecutionOwner().get());
assertThat(errorActionList, Matchers.not(Matchers.empty()));
for (ErrorAction e : errorActionList) {
assertEquals(ProxyException.class, e.getError().getClass());
}
}
public static class X extends Exception {
final NullObject nil = NullObject.getNullObject();
}

}

0 comments on commit a48460e

Please sign in to comment.
You can’t perform that action at this time.