Return-Path: Delivered-To: apmail-commons-issues-archive@minotaur.apache.org Received: (qmail 66580 invoked from network); 17 Jan 2011 05:58:08 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 17 Jan 2011 05:58:08 -0000 Received: (qmail 13538 invoked by uid 500); 17 Jan 2011 05:58:07 -0000 Delivered-To: apmail-commons-issues-archive@commons.apache.org Received: (qmail 13321 invoked by uid 500); 17 Jan 2011 05:58:05 -0000 Mailing-List: contact issues-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: issues@commons.apache.org Delivered-To: mailing list issues@commons.apache.org Received: (qmail 13312 invoked by uid 99); 17 Jan 2011 05:58:05 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 17 Jan 2011 05:58:05 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.22] (HELO thor.apache.org) (140.211.11.22) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 17 Jan 2011 05:58:04 +0000 Received: from thor (localhost [127.0.0.1]) by thor.apache.org (8.13.8+Sun/8.13.8) with ESMTP id p0H5vhhY007411 for ; Mon, 17 Jan 2011 05:57:44 GMT Message-ID: <12689967.7501295243863842.JavaMail.jira@thor> Date: Mon, 17 Jan 2011 00:57:43 -0500 (EST) From: "Henri Yandell (JIRA)" To: issues@commons.apache.org Subject: [jira] Updated: (LANG-647) ToStringBuilder output makes it difficult to distinguich between an empty String array and an array of one empty String MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/LANG-647?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Henri Yandell updated LANG-647: ------------------------------- Fix Version/s: (was: 3.0) 3.1 I don't think the requested change should be done; it makes an array with an empty String equal an array with a String containing two double quotes. Putting quotes around all Strings would be one solution; but this merely opens up a whole slew of problems in ToStringBuilder's default implementation; namely that it doesn't show types. "1", '1' and (int)1 all look the same. As do "true" and (boolean)true. I think the solution here is to have a StringStyle that displays types. Moving to 3.1 as this wouldn't be a backwards incompatibility. > ToStringBuilder output makes it difficult to distinguich between an empty String array and an array of one empty String > ----------------------------------------------------------------------------------------------------------------------- > > Key: LANG-647 > URL: https://issues.apache.org/jira/browse/LANG-647 > Project: Commons Lang > Issue Type: Improvement > Components: lang.builder.* > Affects Versions: 2.5 > Reporter: pascal jacob > Priority: Minor > Fix For: 3.1 > > > ToStringBuilder output is the same for an empty array (i.e. new String[0]) and for an array containing only a single empty string (i.e. new String[] { "" } ). This makes it difficult in some case to see the true nature of arrays. > For example I once had a JUnit test case that print the following trace failure: > java.lang.AssertionError: > Expected: > got: > Apparently the two objects look like the same! But they are not: one had an empty array; the other had an array with only a single empty string. With a customized ToStringStyle the difference became apparent: > Expected: > got: > The fix is simple, change the method: protected void appendDetail(StringBuffer buffer, String fieldName, Object value) to: > protected void appendDetail(StringBuffer buffer, String fieldName, Object value) { > if((value instanceof String) && ((String)value).isEmpty()) { > buffer.append("\"\""); > } > else { > super.appendDetail(buffer, fieldName, value); > } > } > > here is the test case that revealed the problem: > public void testToStringBuilder() { > ToStringBuilder builder1 = new ToStringBuilder("Builder1"); > builder1.append("empty array", new String[0]); > builder1.append("array of one empty string", new String[] { "" }); > builder1.append("array of two empty strings", new String[] { "", "" }); > String builder1Result = builder1.toString(); > System.out.println(builder1Result); > // ----- > ToStringBuilder builder2 = new ToStringBuilder("Builder2", new ToStringStyle() { > @Override > protected void appendDetail(StringBuffer buffer, String fieldName, Object value) { > if((value instanceof String) && ((String)value).isEmpty()) { > buffer.append("\"\""); > } > else { > super.appendDetail(buffer, fieldName, value); > } > } > }); > builder2.append("empty array", new String[0]); > builder2.append("array of one empty string", new String[] { "" }); > builder2.append("array of two empty strings", new String[] { "", "" }); > String builder2Result = builder2.toString(); > System.out.println(builder2Result); > } -- This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online.