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

@Lazy transform should check for explicit getters/setters

    XMLWordPrintableJSON

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 4.0.0-alpha-3
    • Component/s: None
    • Labels:

      Description

      The @Lazy transform renames the backing field to "make it more hidden" and doesn't provide a setter, hence making the field read-only (apart from reflection tricks).

      class Zoo {
          @Lazy String animal = { 'sloth' }()
          //void setAnimal(String animal) { this.animal = animal }
          //String getAnimal() { this.animal }
      }
      

      Here animal becomes $animal. The intention is to disallow the fields use anymore apart from the sanctioned initialization code provided by the transform. No attempt is made to rename usages of the field that may otherwise occur within the class. Hence adding an explicit getter or setter in the normal way yields a StackOverflowError when trying to access the original property or MissingFieldException if trying to access the field directly, i.e. this.@animal. The transform should instead issue an error if explicit getters/setters are found. It would still be possible to access the $animal field (which in general may or may not be initialized) if there was really a need, just not in the standard getter or setter.

        Attachments

          Activity

            People

            • Assignee:
              paulk Paul King
              Reporter:
              paulk Paul King
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0h
                0h
                Logged:
                Time Spent - 0.5h
                0.5h