Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 566504

Summary: [toString] Source -> Generate toString() fails for String[][]
Product: [Eclipse Project] JDT Reporter: Paul Nahay <pnahay>
Component: UIAssignee: JDT-UI-Inbox <jdt-ui-inbox>
Status: CLOSED NOT_ECLIPSE QA Contact:
Severity: normal    
Priority: P3 CC: julian.honnen, noopur_gupta, paul-eclipse
Version: 4.16   
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard:

Description Paul Nahay CLA 2020-08-29 19:50:36 EDT
Source -> Generate toString() fails for String[][]. A toString() method IS generated, but it is malformed. See code, and output, which is a string that has 4 left brackets in it, but only 2 matching right brackets.

import java.util.Arrays;

public class GenerateToStringBug {
	
	public static void main(String[] args) {
		System.out.println(new GenerateToStringBug());
	}

	String[][] array = {{"one", "two"}, {"three", "four"}};

	@Override
	public String toString() {
		return "GenerateToStringBug [array=" + Arrays.toString(array) + "]";
		// OUTPUT: GenerateToStringBug [array=[[Ljava.lang.String;@2f92e0f4, [Ljava.lang.String;@28a418fc]]
	}
}
Comment 1 Julian Honnen CLA 2020-08-31 02:31:08 EDT
That works as expected. The unbalanced brackets are from the toString() of the inner arrays:

{"one", "two"}.toString() => "[Ljava.lang.String;@2f92e0f4"

There's no Arrays::toString alternative for nested arrays in the JDK, so you'd have to implement your own.