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

InnerClassCompletionVisitor does not overwrite existing propertyMissing/methodMissing impls completely

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.2.1
    • Fix Version/s: 2.2.2, 2.3.0-beta-1
    • Component/s: class generator
    • Labels:
      None

      Description

      InnerClassCompletionVisitor adds methodMissing and propertyMissing impls to static inner classes.

          public java.lang.Object methodMissing(java.lang.String name, java.lang.Object args) {
              return Container."$name"(* args )
          }
      
          public void propertyMissing(java.lang.String name, java.lang.Object val) {
              Container."$name" = val 
          }
      
          public java.lang.Object propertyMissing(java.lang.String name) {
              return Container."$name"
          }
      

      The issue is, whenever one of these is defined by the user InnerClassCompletionVisitor takes the already existing MethodNode and replaces its method block.

      This leads to errors if the custom impl has chosen other parameter names as the InnerClassCompletionVisitor code expects:

      class A {
      
        static class B {
        
            def propertyMissing(String name, Object myValue) {
                return value
            }
        }
      }
      
      def b = new A.B()
      b.a = 'test' // groovy.lang.MissingFieldException: No such field: val for class: A
      

      The MissingFieldException is thrown because there is no parameter named val in the user-defined method interface of propertyMissing.

        Attachments

          Activity

            People

            • Assignee:
              asteingress Andre Steingress
              Reporter:
              andre.steingress Andre Steingress
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: