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 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
    • Number of attachments :
      0

      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

        No work has yet been logged on this issue.

          People

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

            Dates

            • Created:
              Updated:
              Resolved: