Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
1.8.1, 1.8.2
-
linux
[tauser02@gfmwsp11lds cps]$ uname -a
Linux gfmwsp11lds.hsi.hughessupply.com 2.6.18-164.el5 #1 SMP Thu Sep 3 04:15:13 EDT 2009 x86_64 x86_64 x86_64 GNU/Linux
[tauser02@gfmwsp11lds ~]$ groovy -v
Groovy Version: 1.8.2 JVM: 1.6.0_20
I also tried it on Groovy 1.8.1
Description
Using the @Log4j annotation on a groovy class that extends java.util.Properties seems to have odd side effects on closures.
import groovy.util.logging.* [new Test1(), new Test2(), new Test3()].each { runTest(it) } def runTest (obj) { try { obj.test() obj.method() println "${obj.getClass()} success" } catch (e) { println "${obj.getClass()} failed $e" } } // classes @Log4j class Test1 { def test () { println '=============================' println 'testing plain Groovy class' println "testing class [${this.getClass().getSimpleName()}]" } def method () { log.debug 'method called, not in closure' ['a', 'b', 'c'].each { log.debug "inside closure [$it]" } } } @Log4j class Test2 extends BaseClass { def test () { println '=============================' println 'testing Groovy class that extends another Groovy class' println "testing class [${this.getClass().getSimpleName()}]" } def method () { log.debug 'method called, not in closure' ['a', 'b', 'c'].each { log.debug "inside closure [$it]" } } } class BaseClass { } @Log4j class Test3 extends java.util.Properties { def test () { println '=============================' println 'testing Groovy class that extends java.util.Properties' println "testing class [${this.getClass().getSimpleName()}]" } def method () { log.debug 'method called, not in closure' ['a', 'b', 'c'].each { log.debug "inside closure [$it]" } } }
log4j.rootLogger=DEBUG, CONSOLE log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout log4j.appender.CONSOLE.layout.ConversionPattern=%d [%t] %-5p %c - %m%n
$ groovy testscript ============================= testing plain Groovy class testing class [Test1] 2011-09-08 15:59:45,757 [main] DEBUG Test1 - method called, not in closure 2011-09-08 15:59:45,759 [main] DEBUG Test1 - inside closure [a] 2011-09-08 15:59:45,759 [main] DEBUG Test1 - inside closure [b] 2011-09-08 15:59:45,759 [main] DEBUG Test1 - inside closure [c] class Test1 success ============================= testing Groovy class that extends another Groovy class testing class [Test2] 2011-09-08 15:59:45,768 [main] DEBUG Test2 - method called, not in closure 2011-09-08 15:59:45,769 [main] DEBUG Test2 - inside closure [a] 2011-09-08 15:59:45,769 [main] DEBUG Test2 - inside closure [b] 2011-09-08 15:59:45,769 [main] DEBUG Test2 - inside closure [c] class Test2 success ============================= testing Groovy class that extends java.util.Properties testing class [Test3] 2011-09-08 15:59:45,771 [main] DEBUG Test3 - method called, not in closure class Test3 failed java.lang.NullPointerException: Cannot invoke method debug() on null object
The problem is on Test3 where the log instance var is null inside the closure, but not outside it.
Only Test 3 has this problem
Attachments
Attachments
Issue Links
- relates to
-
GROOVY-6144 Confusing treatment of m['foo'], m.get('foo'), m.foo, m.getFoo() for Maps
- Closed
-
GROOVY-8065 Map created as org.springframework.http.HttpHeaders is empty in 2.4.8, works fine in 2.4.7
- Closed
-
GROOVY-8074 @CompileStatic class property accessed instead of map property
- Closed
-
GROOVY-8555 The private keyword of an instance variable is causing a behavior change in a map class
- Closed
-
GROOVY-11223 STC: error message for inaccessible setter is not too helpful
- Closed
-
GROOVY-5491 HashMap subclass property access inconsistent
- Closed
-
GROOVY-662 Extending HashMap and adding JavaBean properties confuses Groovy
- Closed