4444import com .thoughtworks .xstream .io .HierarchicalStreamReader ;
4545import com .thoughtworks .xstream .io .HierarchicalStreamWriter ;
4646import com .thoughtworks .xstream .mapper .Mapper ;
47- import groovyjarjarasm .asm .MethodTooLargeException ;
4847import groovy .lang .GroovyShell ;
4948import hudson .ExtensionList ;
5049import hudson .model .Action ;
5453import jenkins .model .Jenkins ;
5554import org .codehaus .groovy .control .ErrorCollector ;
5655import org .codehaus .groovy .control .MultipleCompilationErrorsException ;
57- import org .codehaus .groovy .control .messages .Message ;
5856import org .jboss .marshalling .Unmarshaller ;
5957import org .jenkinsci .plugins .workflow .actions .ErrorAction ;
6058import 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