[ 
https://issues.apache.org/jira/browse/GROOVY-7371?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15443353#comment-15443353
 ] 

paolo di tommaso commented on GROOVY-7371:
------------------------------------------

I'm getting this problem in the nextflow project  
https://github.com/nextflow-io/nextflow

It's really weird, also because the generated bytecode looks fine: 

{code}

    public int bar() {
        java.lang.Integer count = 0
        if (log.isTraceEnabled()) {
            log.isTraceEnabled() ? log.trace("$(count++)") : null
        }
        return count 
    }

    public int foo() {
        java.lang.Integer count = 0
        log.isTraceEnabled() ? log.trace("$(count++)") : null
        return count 
    }
{code}

Could be possible that for some reason the GString in the `foo` method is 
evaluated to be passed as String to the `trace` method ? 


> AST xform @Slf4j does not check level guard
> -------------------------------------------
>
>                 Key: GROOVY-7371
>                 URL: https://issues.apache.org/jira/browse/GROOVY-7371
>             Project: Groovy
>          Issue Type: Bug
>    Affects Versions: 2.3.11
>            Reporter: paolo di tommaso
>            Priority: Minor
>
> Groovy logging AST transformation is supposed to  "wrap all calls to 
> log.level() into the appropriate log.isLevelEnabled guard, depending on the 
> underlying framework " 
> http://groovy-lang.org/metaprogramming.html#_logging_improvements
> However the following test fails: 
> {code}
> @groovy.util.logging.Slf4j 
> class TestLog {
>   def bar () {
>     int count=0
>     if( log.isTraceEnabled() )  {
>         log.trace "${count++}"
>     }
>     return count
>   }
>   def foo () {
>     int count=0
>     log.trace "${count++}"
>     return count
>   }
> }
> assert new TestLog().bar() == 0
> assert new TestLog().foo() == 0 
> Assertion failed: 
> assert new TestLog().foo() == 0
>        |             |     |
>        |             1     false
>        TestLog@416b8a53
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to