[
https://issues.apache.org/jira/browse/GROOVY-5001?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Eric Milles reassigned GROOVY-5001:
-----------------------------------
Assignee: Eric Milles
> Map access is given higher precedence when trying to access fields/properties
> in classes which implement java.util.Map or extend java.util.HashMap or
> java.util.Properties
> --------------------------------------------------------------------------------------------------------------------------------------------------------------------------
>
> Key: GROOVY-5001
> URL: https://issues.apache.org/jira/browse/GROOVY-5001
> Project: Groovy
> Issue Type: Bug
> Components: groovy-runtime
> Affects Versions: 1.8.1, 1.8.2
> Environment: 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
> Reporter: ericksn
> Assignee: Eric Milles
> Priority: Major
> Attachments: screenshot-1.png
>
>
> Using the @Log4j annotation on a groovy class that extends
> java.util.Properties seems to have odd side effects on closures.
> {code:title=testscript}
> 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]"
> }
> }
> }
> {code}
> {code:title=log4j.properties}
> 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
> {code}
> {noformat}
> $ 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
> {noformat}
> 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
--
This message was sent by Atlassian Jira
(v8.20.1#820001)