Permalink
Browse files

fix for GRAILS-7601 "MissingPropertyException for 'log' after control…

…ler reload"
  • Loading branch information...
1 parent 837a08f commit 70102e891f0574f44d295d7f3732c71b69322401 @graemerocher graemerocher committed Jun 9, 2011
@@ -25,7 +25,6 @@
import org.codehaus.groovy.ast.expr.MethodCallExpression;
import org.codehaus.groovy.classgen.GeneratorContext;
import org.codehaus.groovy.control.SourceUnit;
-import org.codehaus.groovy.grails.commons.GrailsResourceUtils;
import org.codehaus.groovy.grails.compiler.injection.AllArtefactClassInjector;
import org.codehaus.groovy.grails.compiler.injection.AstTransformer;
@@ -47,11 +46,11 @@
public static final String FILTERS_ARTEFACT_TYPE = "filters";
public void performInjection(SourceUnit source, GeneratorContext context, ClassNode classNode) {
- final FieldNode existingField = classNode.getField(LOG_PROPERTY);
+ final FieldNode existingField = classNode.getDeclaredField(LOG_PROPERTY);
if (existingField == null && !classNode.isInterface()) {
final String path = source.getName();
- String artefactType = path != null ? GrailsResourceUtils.getArtefactDirectory(path) : null;
+ String artefactType = path != null ? org.codehaus.groovy.grails.io.support.GrailsResourceUtils.getArtefactDirectory(path) : null;
// little bit of a hack, since filters aren't kept in a grails-app/filters directory as they probably should be
if (artefactType != null && CONF_DIR.equals(artefactType) && classNode.getName().endsWith(FILTERS_ARTEFACT_TYPE_SUFFIX)) {
@@ -7,6 +7,31 @@ import spock.lang.Specification
class LoggingTransformerSpec extends Specification {
+ def "Test log field with inheritance"() {
+ given:
+ def gcl = new GrailsAwareClassLoader()
+ def transformer = new LoggingTransformer()
+ gcl.classInjectors = [transformer] as ClassInjector[]
+
+ when:
+ gcl.parseClass('''
+class BaseController {}
+''')
+ def cls = gcl.parseClass('''
+
+class LoggingController extends BaseController{
+ def index() {
+ log.debug "message"
+ return log
+ }
+}
+''', "foo/grails-app/controllers/LoggingController.groovy")
+ def controller = cls.newInstance()
+ Log log = controller.index()
+
+ then:
+ log instanceof Log
+ }
def "Test added log field"() {
given:
def gcl = new GrailsAwareClassLoader()

0 comments on commit 70102e8

Please sign in to comment.