Groovy
  1. Groovy
  2. GROOVY-4814

When working with ClassNodes, sometimes need to call getFields() before getField() will work (lazy init)

    Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 1.8.0
    • Fix Version/s: 1.8.1, 1.9-beta-1
    • Component/s: Compiler
    • Labels:
      None

      Description

      Here is a test that I've been running in the LazyInitOnClassNodeTest class.

      void testLazyInit2() {
      		ClassNode listType = ClassHelper.make(RetentionPolicy.class)
      //		listType.getFields()
      		FieldNode fn = listType.getField "SOURCE"
      		assert fn!=null		
      	}
      

      Like that, it will fail. If the call to getFields() is uncommented, it will pass. This is due to lazy class initialization not running if getFields() isnt run (or some other method that triggers the lazy init). I fixed it by adding:

      if (!redirect().lazyInitDone) redirect().lazyClassInit();

      to getDeclaredField() (used from getField) - but that may not be the best way.

      I haven't checked whether the same problem also affects methods/etc.

        Activity

        Andy Clement created issue -
        Paul King made changes -
        Field Original Value New Value
        Fix Version/s 1.9-beta-1 [ 17153 ]
        Status Open [ 1 ] Resolved [ 5 ]
        Assignee Paul King [ paulk ]
        Resolution Fixed [ 1 ]
        Fix Version/s 1.8.1 [ 17223 ]
        Paul King made changes -
        Status Resolved [ 5 ] Closed [ 6 ]
        Mark Thomas made changes -
        Project Import Sun Apr 05 13:32:57 UTC 2015 [ 1428240777691 ]
        Mark Thomas made changes -
        Workflow jira [ 12733742 ] Default workflow, editable Closed status [ 12745543 ]
        Mark Thomas made changes -
        Project Import Mon Apr 06 02:11:23 UTC 2015 [ 1428286283443 ]
        Mark Thomas made changes -
        Workflow jira [ 12971266 ] Default workflow, editable Closed status [ 12979044 ]

          People

          • Assignee:
            Paul King
            Reporter:
            Andy Clement
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development