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

Accessing outer properties/methods from inner classes results in NPE

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.7.4, 1.8-beta-1
    • 1.7.5, 1.8-beta-2
    • None
    • None

    Description

      The outer property access and method invocations from inner class seem to be resulting in NPE, as shown by examples below:

      Case 1: Outer property access from inner class

      class ReflectionToolboxTest {
         static final PROPERTY_VALUE = "property_value"
         class Bean {
             String property = PROPERTY_VALUE
         }
      
         def bean = new Bean()
      }
      
      def test = new ReflectionToolboxTest()
      

      results in

      java.lang.NullPointerException
          at ReflectionToolboxTest$Bean.propertyMissing(Script1.groovy)
          at ReflectionToolboxTest$Bean.<init>(Script1.groovy)
          at ReflectionToolboxTest.<init>(Script1.groovy:7)
          at Script1.run(Script1.groovy:10)
      

      Case 2: Outer method access from inner class

      class Dummy {
         def foo(){}
         class Bean {
             String property = foo()
          }
         def bean = new Bean()
      }
      new Dummy()
      

      results in

      java.lang.NullPointerException
          at Dummy$Bean.methodMissing(Script1.groovy)
          at Dummy$Bean.<init>(Script1.groovy:4)
          at Dummy.<init>(Script1.groovy:6)
          at Script1.run(Script1.groovy:8)
      

      Attachments

        Activity

          People

            roshandawrani Roshan Dawrani
            roshandawrani Roshan Dawrani
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: