[ https://issues.apache.org/jira/browse/GROOVY-7233?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Paul King resolved GROOVY-7233. ------------------------------- Resolution: Fixed Assignee: Paul King Fix Version/s: 3.0.0-alpha-4 Proposed modified PR merged. Thanks [~bdkosher] for the original work. > Configurable @Log AST logger field access modifiers > --------------------------------------------------- > > Key: GROOVY-7233 > URL: https://issues.apache.org/jira/browse/GROOVY-7233 > Project: Groovy > Issue Type: Improvement > Reporter: Joe Wolf > Assignee: Paul King > Priority: Minor > Labels: ast, logging > Fix For: 3.0.0-alpha-4 > > Time Spent: 0.5h > Remaining Estimate: 0h > > On rare occasions, it can be desirable for a logger to be non-private. > Consider a @Log-annotated class with a method containing anonymous closures > that log using the class's AST-injected logger. > {code:title=BaseClient.groovy|borderStyle=solid} > @Grab(group='org.codehaus.groovy.modules.http-builder', > module='http-builder', version='0.7.1' ) > import groovy.util.logging.* > import groovyx.net.http.* > import static groovyx.net.http.ContentType.* > import static groovyx.net.http.Method.* > @Log > class BaseClient { > def fetchDocuments(String id) { > new HTTPBuilder('https://tsdrapi.uspto.gov').request(GET, XML) { > log.fine "Retrieving documents for case $id..." > uri.path = "/ts/cd/casedocs/$id/info.xml" > response.success = { resp, xml -> > log.fine "..successfully received data for $id" > xml > } > } > } > } > {code} > Invoking {{new BaseClient().fetchDocuments('86375968')}} works as expected. > However, if a subclass is written that invokes the parent method, such as: > {code:title=Client.groovy|borderStyle=solid} > class Client extends BaseClient { > def getDocuments() { > fetchDocuments('86375968') > } > } > {code} > Invoking {{new Client().documents}} surprisingly results in a > {{groovy.lang.MissingPropertyException: No such property: log for class: > groovyx.net.http.HTTPBuilder$RequestConfigDelegate}} error. I believe this is > due to the closure delegation being done via the subclass, which does not > have visibility to the parent class's private fields--namely, the injected > log field. > Other than a design change, or by defining a new log variable within the > parent method ({{def log = log}}, this problem can be avoided if the log > field had protected visibility. > Here's an example of how it would look. > {code} > @Log(access='protected') > class SomeClass {} > {code} > results in > {code} > public class SomeClass { > protected static transient final Logger log; > } > {code} -- This message was sent by Atlassian JIRA (v7.6.3#76005)