Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-8978

NPE when accessing protected method from subclass clone

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.5.6
    • Fix Version/s: 3.0.0-beta-1, 2.5.7
    • Component/s: None
    • Labels:
      None

      Description

      I'm getting a NPE when running this snippet:

      @groovy.transform.CompileStatic
      class LazyMap implements Map<String,Object> {
      
          @Delegate protected Map<String,Object> target
      
          LazyMap() {
              target = new HashMap<>()
          }
      }
      
      @groovy.transform.CompileStatic
      class TaskConfig extends LazyMap implements Cloneable {
      
          TaskConfig() {  }
      
          TaskConfig clone() {
              def copy = (TaskConfig)super.clone()
              copy.target = new HashMap<>(this.target)
              return copy
          }
      }
      

      The problem is that `this.target` in the clone method is evaluated to `null`. It works fine if the classes are not declared CompileStatic. It was also working fine with groovy version prior to 2.5.6.

        Attachments

          Activity

            People

            • Assignee:
              paulk Paul King
              Reporter:
              pablo72 paolo di tommaso
            • Votes:
              1 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: