Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #64 from jglick/nested-error-fields-JENKINS-49025
[JENKINS-49025] Extending JENKINS-34488 fix yet again
  • Loading branch information
abayer committed Feb 15, 2018
2 parents 1f5461a + a48460e commit 43fc2f2
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 9 deletions.
Expand Up @@ -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.
Expand All @@ -44,6 +46,13 @@ public class ErrorAction implements PersistentAction {
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;
}
Expand All @@ -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;
}
Expand Down
Expand Up @@ -46,6 +46,7 @@

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

/**
* Tests for {@link ErrorAction}
Expand Down Expand Up @@ -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 43fc2f2

Please sign in to comment.