Skip to content

Commit fa95de7

Browse files
committed
CpsFlowExecution.parseScript(): handle MethodTooLargeException without importing the class
Signed-off-by: Jim Klimov <[email protected]>
1 parent ffe1f1a commit fa95de7

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

plugin/src/main/java/org/jenkinsci/plugins/workflow/cps/CpsFlowExecution.java

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
import com.thoughtworks.xstream.io.HierarchicalStreamReader;
4545
import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
4646
import com.thoughtworks.xstream.mapper.Mapper;
47-
import groovyjarjarasm.asm.MethodTooLargeException;
4847
import groovy.lang.GroovyShell;
4948
import hudson.ExtensionList;
5049
import hudson.model.Action;
@@ -54,7 +53,6 @@
5453
import jenkins.model.Jenkins;
5554
import org.codehaus.groovy.control.ErrorCollector;
5655
import org.codehaus.groovy.control.MultipleCompilationErrorsException;
57-
import org.codehaus.groovy.control.messages.Message;
5856
import org.jboss.marshalling.Unmarshaller;
5957
import org.jenkinsci.plugins.workflow.actions.ErrorAction;
6058
import org.jenkinsci.plugins.workflow.cps.persistence.PersistIn;
@@ -642,17 +640,25 @@ private CpsScript parseScript() throws IOException {
642640
for (Entry<String, String> e : loadedScripts.entrySet()) {
643641
shell.reparse(e.getKey(), e.getValue());
644642
}
645-
} catch (MethodTooLargeException | MultipleCompilationErrorsException x) {
646-
MethodTooLargeException mtlEx = null;
643+
} catch (Exception x) {
644+
// Suspected groovyjarjarasm.asm.MethodTooLargeException or a
645+
// org.codehaus.groovy.control.MultipleCompilationErrorsException
646+
// whose collection of errors refers to MethodTooLargeException.
647+
// Per review comments, we do not want to statically compile a
648+
// dependency on the groovyjarjarasm.asm.MethodTooLargeException
649+
// internals, so gauge hitting it via String name comparisons.
650+
// Other cases may be (subclasses of) RuntimeException or Error.
651+
Exception mtlEx = null;
647652
int ecCount = 0;
648653

654+
// Clean up first
649655
closeShells();
650656

651-
if (x instanceof MethodTooLargeException) {
652-
mtlEx = (MethodTooLargeException)x;
657+
if (x.getClass().getSimpleName().equals("MethodTooLargeException")) {
658+
mtlEx = x;
653659
ecCount = 1;
654660
} else if (x instanceof MultipleCompilationErrorsException) {
655-
ErrorCollector ec = ((MultipleCompilationErrorsException)x).getErrorCollector();
661+
ErrorCollector ec = ((MultipleCompilationErrorsException) x).getErrorCollector();
656662
ecCount = ec.getErrorCount();
657663

658664
for (int i = 0; i < ecCount; i++) {
@@ -661,14 +667,14 @@ private CpsScript parseScript() throws IOException {
661667
continue;
662668

663669
LOGGER.log(Level.FINE, "Collected Exception #" + i + ": " + ex.toString());
664-
if (ex instanceof MethodTooLargeException) {
665-
mtlEx = (MethodTooLargeException) ex;
670+
if (ex.getClass().getSimpleName().equals("MethodTooLargeException")) {
671+
mtlEx = ex;
666672
break;
667673
}
668674
}
669675
}
670676

671-
if (mtlEx == null) {
677+
if (mtlEx == null || ecCount < 1) {
672678
// Some other exception type, or collection did not include MTL, rethrow as-is
673679
throw x;
674680
}
@@ -696,9 +702,6 @@ private CpsScript parseScript() throws IOException {
696702
//throw new RuntimeException(msg, mtlEx);
697703
throw new RuntimeException(msg);
698704
}
699-
} catch (RuntimeException | Error x) {
700-
closeShells();
701-
throw x;
702705
}
703706

704707
s.execution = this;

0 commit comments

Comments
 (0)