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

println is inconsistent

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.6-rc-1
    • 1.6-rc-2
    • groovy-jdk
    • None

    Description

      The following test case fails with Groovy version 1.5.6.

      NEWLINE = System.getProperty("line.separator")
      
      void doTest(def param) {
      	try {
      		StringWriter sw1 = new StringWriter()
      		StringWriter sw2 = new StringWriter()
      		StringWriter sw3 = new StringWriter()
      
      		sw1.write(String.valueOf(param))
      		sw2.print(String.valueOf(param))
      		new PrintWriter(sw3).print(param)
      
      		assert sw1.toString() == sw2.toString()
      		assert sw1.toString() == sw3.toString()
      
      		sw1 = new StringWriter()
      		sw2 = new StringWriter()
      		sw3 = new StringWriter()
      
      		sw1.write(String.valueOf(param))
      		sw1.write(NEWLINE)
      		sw2.println(param)
      		new PrintWriter(sw3).println(param)
      
      		assert sw1.toString() == sw2.toString()
      		assert sw1.toString() == sw3.toString()
      	}
      	catch (AssertionError e) {
      		System.err.println(param)
      
      		throw e
      	}
      }
      
      doTest(null)
      doTest("foo")
      doTest(true)
      doTest(false)
      doTest((byte)123)
      doTest((short)1234)
      doTest(new Integer(1234))
      doTest(new Long(9999999999))
      doTest(new Float(1234.5678))
      doTest(new Double(1234.5678))
      doTest(new BigInteger("123456789012345678901234567890"))
      doTest(new BigDecimal("12345678901234567890.1234567890123456789"))
      doTest(new Date())
      doTest(new StringBuffer("bar"))
      doTest([null, "foo", true, false, new Integer(1234)])
      doTest(["foo" : "bar", "true": true, "int": new Integer(1234)])
      

      Attachments

        1. Groovy3237Bug.groovy
          1 kB
          James P. White

        Issue Links

          Activity

            People

              jimwhite James P. White
              veita Alexander Veit
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: