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

MissingPropertyException when accessing @Log-generated log field from a CGLib-proxied outer class

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 3.0.5, 2.5.13
    • Fix Version/s: 2.5.14, 3.0.6
    • Component/s: None
    • Labels:
      None

      Description

      There appears to be a regression in Groovy 2.5.13. It can be reproduced with the following script:

      import groovy.util.logging.Log
      import java.lang.reflect.Method
      import java.util.function.Consumer
      import net.sf.cglib.proxy.MethodInterceptor
      import net.sf.cglib.proxy.MethodProxy
      import net.sf.cglib.proxy.Enhancer
      
      @Log
      @Grab("cglib:cglib:3.3.0")
      class Thing {
      
      	void method() {
      		Runnable nested = {
      			log.info("hello")
      		}
      		nested.run()
      	}
      
      }
      
      def enhancer = new Enhancer()
      enhancer.superclass = Thing
      enhancer.callback = { obj, method, args, proxy -> 
          proxy.invokeSuper(obj, args);
      } as MethodInterceptor
      
      def proxy = enhancer.create()
      proxy.method()
      

      When run with Groovy 2.5.12, hello is logged:

      $ sdk use groovy 2.5.12
      
      Using groovy version 2.5.12 in this shell.
      $ groovy logging.groovy
      Jul 23, 2020 10:20:05 AM java_util_logging_Logger$info$0 call
      INFO: hello
      

      With Groovy 2.5.13, the log field cannot be found:

      $ sdk use groovy 2.5.13
      
      Using groovy version 2.5.13 in this shell.
      $ groovy logging.groovy
      Caught: groovy.lang.MissingPropertyException: No such property: log for class: Thing$$EnhancerByCGLIB$$ac2265fe
      groovy.lang.MissingPropertyException: No such property: log for class: Thing$$EnhancerByCGLIB$$ac2265fe
      	at net.sf.cglib.proxy.MethodProxy$invokeSuper.call(Unknown Source)
      	at logging$_run_closure1.doCall(logging.groovy:24)
      	at com.sun.proxy.$Proxy16.intercept(Unknown Source)
      	at Thing$$EnhancerByCGLIB$$ac2265fe.getProperty(<generated>)
      	at Thing$_method_closure1.doCall(logging.groovy:14)
      	at Thing$_method_closure1.doCall(logging.groovy)
      	at Thing.method(logging.groovy:16)
      	at Thing$$EnhancerByCGLIB$$ac2265fe.CGLIB$method$0(<generated>)
      	at Thing$$EnhancerByCGLIB$$ac2265fe$$FastClassByCGLIB$$704960d8.invoke(<generated>)
      	at net.sf.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
      	at net.sf.cglib.proxy.MethodProxy$invokeSuper.call(Unknown Source)
      	at logging$_run_closure1.doCall(logging.groovy:24)
      	at com.sun.proxy.$Proxy16.intercept(Unknown Source)
      	at Thing$$EnhancerByCGLIB$$ac2265fe.method(<generated>)
      	at Thing$$EnhancerByCGLIB$$ac2265fe$method.call(Unknown Source)
      	at logging.run(logging.groovy:28)
      

      The problem does not occur if Thing is not proxied or when trying to access a field that explicit declared rather than being created via @Log.

        Attachments

          Activity

            People

            • Assignee:
              emilles Eric Milles
              Reporter:
              awilkinson Andy Wilkinson
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: