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

Can't assign a field with the result of a method call of the same name from a base class

Attach filesAttach ScreenshotVotersWatch issueWatchersCreate sub-taskLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 3.0.7
    • Fix Version/s: 2.5.15, 3.0.8, 4.0.0-alpha-3
    • Component/s: None
    • Labels:
      None

      Description

      Having a method in a base class and using that method in an assignment in an inheriting class to assign a field of the same name as that method causes a NullPointerException.

      Try executing the attached script with Groovy 3.0.7. It will yield:

      ❯ groovy test.groovy
      Caught: java.lang.NullPointerException
      java.lang.NullPointerException
      	at Child.setup(test.groovy:11)
      	at Child$setup.call(Unknown Source)
      	at test.run(test.groovy:16)
      	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      

      As a work around the method call to foo() can explicitly be prefixed with `super.`

        Attachments

          Activity

            People

            • Assignee:
              emilles Eric Milles
              Reporter:
              britter Benedikt Ritter

              Dates

              • Created:
                Updated:
                Resolved:

                Issue deployment