Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 5F99D200C6A for ; Wed, 19 Apr 2017 18:01:48 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 5E066160B94; Wed, 19 Apr 2017 16:01:48 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id A4432160B86 for ; Wed, 19 Apr 2017 18:01:47 +0200 (CEST) Received: (qmail 74422 invoked by uid 500); 19 Apr 2017 16:01:45 -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 74411 invoked by uid 99); 19 Apr 2017 16:01:45 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 19 Apr 2017 16:01:45 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id 5B237185E94 for ; Wed, 19 Apr 2017 16:01:45 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -99.202 X-Spam-Level: X-Spam-Status: No, score=-99.202 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, RP_MATCHES_RCVD=-0.001, SPF_PASS=-0.001, USER_IN_WHITELIST=-100] autolearn=disabled Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id A62O3vIzgKHD for ; Wed, 19 Apr 2017 16:01:43 +0000 (UTC) Received: from mailrelay1-us-west.apache.org (mailrelay1-us-west.apache.org [209.188.14.139]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with ESMTP id 85C205F1D5 for ; Wed, 19 Apr 2017 16:01:42 +0000 (UTC) Received: from jira-lw-us.apache.org (unknown [207.244.88.139]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id D687CE06BB for ; Wed, 19 Apr 2017 16:01:41 +0000 (UTC) Received: from jira-lw-us.apache.org (localhost [127.0.0.1]) by jira-lw-us.apache.org (ASF Mail Server at jira-lw-us.apache.org) with ESMTP id 90B0A21B45 for ; Wed, 19 Apr 2017 16:01:41 +0000 (UTC) Date: Wed, 19 Apr 2017 16:01:41 +0000 (UTC) From: "Pascal Schumacher (JIRA)" To: issues@commons.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Updated] (LANG-647) ToStringBuilder output makes it difficult to distinguish 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 archived-at: Wed, 19 Apr 2017 16:01:48 -0000 [ https://issues.apache.org/jira/browse/LANG-647?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Pascal Schumacher updated LANG-647: ----------------------------------- Summary: ToStringBuilder output makes it difficult to distinguish between an empty String array and an array of one empty String (was: ToStringBuilder output makes it difficult to distinguich between an empty String array and an array of one empty String) > ToStringBuilder output makes it difficult to distinguish 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: Patch Needed > > > 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 was sent by Atlassian JIRA (v6.3.15#6346)