Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-39719

MultipleCompilationErrorsException: You are not allowed to override the final method __cps__2() from class …

    XMLWordPrintable

    Details

    • Similar Issues:

      Description

      When importing an internal library (as described at https://github.com/jenkinsci/workflow-cps-global-lib-plugin), I'm encountering an issue:

      org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: 
      WorkflowScript: -1: You are not allowed to override the final method ___cps___2() from class 'com.acme.foo.test.MyTest'. 
      @ line -1, column -1. 
      1 error 
      at org.codehaus.groovy.control.ErrorCollector.failIfErrors(ErrorCollector.java:310) 
      at org.codehaus.groovy.control.CompilationUnit.applyToPrimaryClassNodes(CompilationUnit.java:1073) 
      at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:591) 
      at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:569) 
      at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:546) 
      at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:298) 
      at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:268) 
      at groovy.lang.GroovyShell.parseClass(GroovyShell.java:688) 
      at groovy.lang.GroovyShell.parse(GroovyShell.java:700) 
      at org.jenkinsci.plugins.workflow.cps.CpsGroovyShell.reparse(CpsGroovyShell.java:67) 
      at org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.parseScript(CpsFlowExecution.java:410) 
      at org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.start(CpsFlowExecution.java:373) 
      at org.jenkinsci.plugins.workflow.job.WorkflowRun.run(WorkflowRun.java:213) 
      at hudson.model.ResourceController.execute(ResourceController.java:98) 
      at hudson.model.Executor.run(Executor.java:410) 
      Finished: FAILURE
      

      Using the following libraries to produce this error:

      workflowLibs/src/com/acme/foo/test/MyTest.groovy:

      #!groovy 
      package com.acme.foo.test 
      class MyTest 
      { 
      def mytest1() {} 
      } 
      

      workflowLibs/src/com/acme/foo/test/MyOtherTest.groovy:

      #!groovy 
      package com.acme.foo.test 
      class MyOtherTest { 
      def test1() {} 
      def test2() {} 
      }
      

      Pipeline content:

      #!groovy 
      import com.acme.foo.test.MyTest 
      import com.acme.foo.test.MyOtherTest 
      
      class MyTestExtended 
      extends MyTest 
      { 
      def mytestfunction() {} 
      } 
      
      node('localhost') { 
      def pipeline = new MyTestExtended() 
      }
      

      Now here's the odd part. The error only manifests for certain class names. The error is thrown with the stack trace described above when the class/file is named "MyTest", "Test2", "Test3", or "What". If I change the name to "Test1" or "DoStuff", the same pipeline finishes successfully.

      Additionally, the second (unused) import in the pipeline script, is required to produce the issue. When I remove the second import statement (import com.acme.foo.test.MyOtherTest), the pipeline passes for all names of the primary class being expanded upon.

        Attachments

          Activity

          Hide
          hemanglavana HemangLavana added a comment -

          This is a blocker issue for us as we are not able to use "@grab" to import apache loggers libraries for use within our workflow code. Please prioritize this so that we can benefit from this feature. PS: we are not able to upgrade to latest jenkins LTS 2.19.2 due to this issue.

          Show
          hemanglavana HemangLavana added a comment - This is a blocker issue for us as we are not able to use "@grab" to import apache loggers libraries for use within our workflow code. Please prioritize this so that we can benefit from this feature. PS: we are not able to upgrade to latest jenkins LTS 2.19.2 due to this issue.
          Hide
          jglick Jesse Glick added a comment -

          Analysis: the class names only matter insofar as they may affect the order in which files are parsed, and the number of methods defined in each class. Basically the issue is manifested under certain conditions when

          • there is a Groovy class defined in a library which defines some methods
          • this class is extended in the main Pipeline script which defines some additional methods

          For every method, Pipeline generates an internal ___cps___NNN method for the CPS transformation. The counter is incremented for each new method, but was effectively being reset at the transition between library and main script. Depending on the exact source structure, it can happen that a main script class was transformed to include a generated method with the same counter as its library superclass, producing an error by the Groovy compiler—though one of dubious correctness, since these are all private static final and so could not have been interpreted as an override (Java correctly permits this).

          Show
          jglick Jesse Glick added a comment - Analysis: the class names only matter insofar as they may affect the order in which files are parsed, and the number of methods defined in each class. Basically the issue is manifested under certain conditions when there is a Groovy class defined in a library which defines some methods this class is extended in the main Pipeline script which defines some additional methods For every method, Pipeline generates an internal ___cps___NNN method for the CPS transformation. The counter is incremented for each new method, but was effectively being reset at the transition between library and main script. Depending on the exact source structure, it can happen that a main script class was transformed to include a generated method with the same counter as its library superclass, producing an error by the Groovy compiler—though one of dubious correctness, since these are all private static final and so could not have been interpreted as an override (Java correctly permits this).

            People

            • Assignee:
              jglick Jesse Glick
              Reporter:
              dtranter Dan Tranter
            • Votes:
              1 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: