groovy-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Pavel Melnikov (JIRA)" <j...@apache.org>
Subject [jira] [Comment Edited] (GROOVY-9014) printf does not respect "out" property
Date Tue, 05 Mar 2019 07:03:00 GMT

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

Pavel Melnikov edited comment on GROOVY-9014 at 3/5/19 7:02 AM:
----------------------------------------------------------------

I've conjured up a minimal example, it works without any JSR223 or whatever:

[^test.groovy]

 

{{def stringWriter = new StringWriter()}}
 {{out = new PrintWriter(stringWriter)}}

{{println "root println" // goes to out}}
 {{printf "root printf\n" // goes to out}}

{{def t1 = {}}
 {{    println "closure println" // goes to out}}
 {{    this.println "closure this.println" // goes to out}}
 {{    out.println "closure out.println" // goes to out}}

{{    printf "closure printf\n" // goes to stdout (bug here) !!}}
 {{    this.printf "closure this.printf\n" //goes to out}}
 {{    out.println "closure out.printf\n" // goes to out}}

{{}}}

{{t1()}}

{{System.out.println("\n====\nOutput that went to out:\n"+stringWriter.toString() )}}

 

 


was (Author: positron96):
I've conjured up a minimal example, it works without any JSR223 or whatever:

test.groovy^!/jira/images/icons/link_attachment_7.gif|width=7,height=7!^

{{}}{{def stringWriter = new StringWriter()}}
 {{out = new PrintWriter(stringWriter)}}

{{println "root println" // goes to out}}
 {{printf "root printf\n" // goes to out}}

{{def t1 = {}}
 {{    println "closure println" // goes to out}}
 {{    this.println "closure this.println" // goes to out}}
 {{    out.println "closure out.println" // goes to out}}

{{    printf "closure printf\n" // goes to stdout (bug here) !!}}
 {{    this.printf "closure this.printf\n" //goes to out}}
 {{    out.println "closure out.printf\n" // goes to out}}

{{}}}

{{t1()}}

{{System.out.println("\n====\nOutput that went to out:\n"+stringWriter.toString() )}}

 

 

> printf does not respect "out" property
> --------------------------------------
>
>                 Key: GROOVY-9014
>                 URL: https://issues.apache.org/jira/browse/GROOVY-9014
>             Project: Groovy
>          Issue Type: Bug
>          Components: groovy-runtime
>         Environment: Ubuntu 18.04.1,
>            Reporter: Pavel Melnikov
>            Priority: Major
>         Attachments: test.groovy
>
>
> I am using groovy to run dynamic scripts from my Java application. I use JSR223 for this.
I am overriding "out" property to redirect script stdout to my own consumer. However, I've
noticed that *printf* inside closures does not respect that property (it always prints to
stdout) while *println* perfectly complies (and prints to whatever specified).
>  
> I beleive this is because of the differences in printf and println in DefaultGroovyMethods.java:
in [https://github.com/apache/groovy/blob/master/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java#L849]
> println uses closure owner while printf does simple System.out.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Mime
View raw message