Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-4309

printf not bound to "out" in groovlet context as in print/println



    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 1.7.3
    • Fix Version/s: 1.7.4, 1.8-beta-1
    • Component/s: Groovlet / GSP
    • Labels:
    • Environment:
      Windows/Linux running within Apache Tomcat/6.0.26


      In groovlet print and println are bound to the response.Writer() or out variable so lone print ... and println ... calls are written th the response output Writer as is calls to out.

      However, printf calls in goovlet context is still bound to System.out so calls to printf write to System.out not out.

      printf method getting invoked is following:

      package org.codehaus.groovy.runtime.DefaultGroovyMethods
          public static void printf(Object self, String format, Object arg) {
              if (self instanceof PrintStream) {
                  printf((PrintStream) self, format, arg);
                  printf(System.out, format, arg); **** this branch is getting invoked

      Object self is Groovlet class itself which is not instance of PrintStream so System.out is getting used.

      Work-around is not using "printf" short-cut but explicitly call print/println and String.format() instead.

      Test output:

      groovy script output:
      1. println test
      2. this is a test
      3. this is a test
      groovlet response:
      1. println test
      3. this is a test
      4. test out.println

      Groovlet test.gsp

      try {
       response.contentType = 'text/plain'
       groovylet = true
      } catch (RuntimeException rte) {
       groovylet = false
      // output to groovlet response
      println "1. println test"
      // in groovyet context this gets output to System.out not out which is bound to response.getWriter()
      printf "2. this is a %s%n", 'test' // this is the problem case in groovlet mode
      print String.format("3. this is a %s%n", 'test')
      if (groovylet) {
        out.println "4. test out.println"




            • Assignee:
              guillaume Guillaume Sauthier
              gjmathews1 jason mathews
            • Votes:
              0 Vote for this issue
              0 Start watching this issue


              • Created: