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

Java code behaves wrong on 2.0.5 but not on 1.8.8

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.0.5
    • Fix Version/s: 2.1.0-rc-1, 2.0.7
    • Component/s: primtive opts
    • Labels:
      None
    • Environment:
      Mac

      Description

      The folowing Java code:

      public class HelloWorld {
      	private String[] names;
      	public String[] getNames() { return names; }
      	public void setNames(String... names) { this.names = names; }
      
      	public String toString() {
      		return "Hello " + join(getNames());
      	}
      
      	private String join(String[] strings) {
      		StringBuilder sb = new StringBuilder();
      		String delim = "";
      		for(String string : strings) {
      			sb.append(delim).append(string);
      			delim = ", ";
      		}
      		return sb.toString();
      	}
      
      	public static void main(String[] args) {
      		HelloWorld helloWorld = new HelloWorld();
      		helloWorld.setNames("Morten", "Riccardo", "Anders");
      		System.out.println(helloWorld.toString());
      	}
      }
      

      produces the same output when compiled in Java or in Groovy 1.8.8 (the names joined with commas), but in Groovy 2.0.5 it produces: Hello [Ljava.lang.String;@4e5a67df

      Found while trying to demonstrate how to simplify Java code in Groovy (not very cool...)

        Attachments

        1. StringArrayAccess.groovy
          1 kB
          Jan Weitz
        2. GROOVY-5812-test.groovy
          3 kB
          Jan Weitz

          Activity

            People

            • Assignee:
              blackdrag Jochen Theodorou
              Reporter:
              sbglasius Soeren Glasius
            • Votes:
              1 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: