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

workflow-cps-global-lib: inheritance (extends) not working

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Major Major
    • workflow-cps-plugin
    • None

      I'm not able to use inheritance in Workflow Global Library code.

      Here is a simple example to demonstrate:

      // src/com/test/MyMap.groovy
      
      package com.test
      
      class MyMap extends HashMap {
      
          def test(String property) {
              super.get(property)
          }
      }
      

          [JENKINS-34428] workflow-cps-global-lib: inheritance (extends) not working

          I can extend abstract classes but calling super.somemethod() from the implementation throws StackOverflow exception

          Zhelyan Panchev added a comment - I can extend abstract classes but calling super.somemethod() from the implementation throws StackOverflow exception

          Jesse Glick added a comment -

          Probably a groovy-cps issue not specific to global libraries.

          Jesse Glick added a comment - Probably a groovy-cps issue not specific to global libraries.

          Josh Theisen added a comment -

          Is there any update to this? I'm running into this same issue... attempting to call

          super.method()

          appears to result in an exception. As shown below, I'm passing in a map but it doesn't think that I am... even the possible solutions show that I should pass a map.

          groovy.lang.MissingMethodException: No signature of method: method() is applicable for argument types: (java.util.LinkedHashMap)
          Possible solutions: method(java.util.Map), method(java.util.Map)

          Josh Theisen added a comment - Is there any update to this? I'm running into this same issue... attempting to call super .method() appears to result in an exception. As shown below, I'm passing in a map but it doesn't think that I am... even the possible solutions show that I should pass a map. groovy.lang.MissingMethodException: No signature of method: method() is applicable for argument types: (java.util.LinkedHashMap) Possible solutions: method(java.util.Map), method(java.util.Map)

          No sure whether this is really the same issue like JENKINS-47143. Are you able to reproduce this using a custom base class without extending HashMap?

          Joerg Schwaerzler added a comment - No sure whether this is really the same issue like JENKINS-47143 . Are you able to reproduce this using a custom base class without extending HashMap ?

          Josh Theisen added a comment - - edited

          Yes, it's definitely not specific to HashMap. Here's a more complete example:

           

          abstract class AbstractClass implements Serializable {
            def jenkins
            AbstractClass(jenkins) {
              this.jenkins = jenkins
            }
            def someMethod(Map input) {
              performSomething(input)
            }
            abstract def performSomething(Map input)
          }
          

          Then in my implementation class

          ImplClass extends AbstractClass {
            //setup stuff here for the class
          
            @Override
            def someMethod(Map input) {
              // Do some extra work here for this specific class
          
              // Then do the rest of the work in the super class
              super.someMethod(input)
            }
          }
          

          When calling the "someMethod" with a Map as input from the implementation class, Jenkins will fail with something like this:

          hudson.remoting.ProxyException: groovy.lang.MissingMethodException: No signature of method: someMethod() is applicable for argument types: (java.util.LinkedHashMap)
          

          Just below, it then even gives possible solutions:

          Possible solutions: someMethod(java.util.Map), someMethod(java.util.Map)

          If I stop overriding the super method with a bit of extra work, Jenkins will call into the abstract class no problem.

          Josh Theisen added a comment - - edited Yes, it's definitely not specific to HashMap. Here's a more complete example:   abstract class AbstractClass implements Serializable { def jenkins AbstractClass(jenkins) { this .jenkins = jenkins } def someMethod(Map input) { performSomething(input) } abstract def performSomething(Map input) } Then in my implementation class ImplClass extends AbstractClass { //setup stuff here for the class @Override def someMethod(Map input) { // Do some extra work here for this specific class // Then do the rest of the work in the super class super .someMethod(input) } } When calling the "someMethod" with a Map as input from the implementation class, Jenkins will fail with something like this: hudson.remoting.ProxyException: groovy.lang.MissingMethodException: No signature of method: someMethod() is applicable for argument types: (java.util.LinkedHashMap) Just below, it then even gives possible solutions: Possible solutions: someMethod(java.util.Map), someMethod(java.util.Map) If I stop overriding the super method with a bit of extra work, Jenkins will call into the abstract class no problem.

          Bruno Conrado Santos added a comment - - edited

          Hi,

          I have the same problem using the last Jenkins LTS version and plugins. We can`t call super methods when super is abstract or not. 

          hudson.remoting.ProxyException: groovy.lang.MissingMethodException: No signature of method: br.com.itau.devopspipelinelibrary.pipeline.impl.JavaPipelineImpl.initialize() is applicable for argument types: (java.lang.String, java.lang.String) values: [migrate-jobs, EB4]

          Do you have some prediction to fix it? 

           

          Thanks

           

          Bruno Conrado Santos added a comment - - edited Hi, I have the same problem using the last Jenkins LTS version and plugins. We can`t call super methods when super is abstract or not.  hudson.remoting.ProxyException: groovy.lang.MissingMethodException: No signature of method: br.com.itau.devopspipelinelibrary.pipeline.impl.JavaPipelineImpl.initialize() is applicable for argument types: (java.lang. String , java.lang. String ) values: [migrate-jobs, EB4] Do you have some prediction to fix it?    Thanks  

            Unassigned Unassigned
            vehovmar Martin Vehovsky
            Votes:
            17 Vote for this issue
            Watchers:
            20 Start watching this issue

              Created:
              Updated: