Return-Path: X-Original-To: apmail-commons-issues-archive@minotaur.apache.org Delivered-To: apmail-commons-issues-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 9F4FE9309 for ; Thu, 1 Mar 2012 18:24:25 +0000 (UTC) Received: (qmail 23145 invoked by uid 500); 1 Mar 2012 18:24:24 -0000 Delivered-To: apmail-commons-issues-archive@commons.apache.org Received: (qmail 23047 invoked by uid 500); 1 Mar 2012 18:24:24 -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 23006 invoked by uid 99); 1 Mar 2012 18:24:24 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 01 Mar 2012 18:24:24 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED,T_RP_MATCHES_RCVD X-Spam-Check-By: apache.org Received: from [140.211.11.116] (HELO hel.zones.apache.org) (140.211.11.116) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 01 Mar 2012 18:24:20 +0000 Received: from hel.zones.apache.org (hel.zones.apache.org [140.211.11.116]) by hel.zones.apache.org (Postfix) with ESMTP id C756532C5 for ; Thu, 1 Mar 2012 18:23:58 +0000 (UTC) Date: Thu, 1 Mar 2012 18:23:58 +0000 (UTC) From: "Thomas Neidhart (Issue Comment Edited) (JIRA)" To: issues@commons.apache.org Message-ID: <924339596.8101.1330626238817.JavaMail.tomcat@hel.zones.apache.org> In-Reply-To: <229120743.41916.1316436429296.JavaMail.tomcat@hel.zones.apache.org> Subject: [jira] [Issue Comment Edited] (LANG-754) embedded objects are not toString-ed like top-level objects MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 X-Virus-Checked: Checked by ClamAV on apache.org [ https://issues.apache.org/jira/browse/LANG-754?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13215870#comment-13215870 ] Thomas Neidhart edited comment on LANG-754 at 3/1/12 6:22 PM: -------------------------------------------------------------- I digged into this problem and the problem you describe occurs only when using setUseShortName(true), and the class is located in the default package and the name is one of [IZFJSBDC], explanation follows. The ToStringStyle uses ClassUtils to get the short name for the class, which uses an internal reverse abbreviation map to resolve primitive array types which are something like [B for a byte[]. Now there seems to be a bug in the ClassUtils.getShortName method as it does this reverse resolve all the time, and if you happen to have a class called B in the default package, it is wrongly identified as byte. was (Author: tn): I digged into this problem and the problem you describe occurs only when using setUseShortName(true), and the class is located in the default package and the name is one of [IZFJSBDC], explanation follows. The ToStringStyle uses ClassUtils to get the short name for the class, which uses an internal reverse abbreviation map to resolve primitive array types which are something like [B for a byte[]. Now there seems to be a bug in the ClassUtils.getShortName method as it does this reverse resolve all the time, and if you happen to have a class called B in the default package, it is wrongly identified as byte. So the fix would be to do the reverse lookup only in case of arrays. > embedded objects are not toString-ed like top-level objects > ----------------------------------------------------------- > > Key: LANG-754 > URL: https://issues.apache.org/jira/browse/LANG-754 > Project: Commons Lang > Issue Type: Bug > Components: lang.builder.* > Affects Versions: 2.5, 3.0.1 > Environment: Linux Ubuntu > java version "1.6.0_24" > Java(TM) SE Runtime Environment (build 1.6.0_24-b07) > Java HotSpot(TM) 64-Bit Server VM (build 19.1-b02, mixed mode) > Reporter: Dominique De Vito > Priority: Minor > Original Estimate: 24h > Remaining Estimate: 24h > > I have a simple class 'A' defined as follows: > ====================================== > public class A { > int p1; > String p2; > B b; > } > ====================================== > While I execute the following instructions: > ToStringBuilder builder = new ReflectionToStringBuilder(a); > System.out.println(builder.toString()); > The output is: > A@3ea981ca[p1=0,p2=,b=B@1ee7b241] > that's normal, without recursion > So, I defined my own style, for recursive toString-ing display: > ====================================== > class MyStyle extends ToStringStyle { > private final static ToStringStyle instance = new MyStyle(); > public MyStyle() { > setArrayContentDetail(true); > setUseShortClassName(true); > setUseClassName(true); > setUseIdentityHashCode(true); > setFieldSeparator(", "); > } > public static ToStringStyle getInstance() { > return instance; > }; > @Override > public void appendDetail(final StringBuffer buffer, final String fieldName, final Object value) { > if (!value.getClass().getName().startsWith("java")) { > buffer.append(ReflectionToStringBuilder.toString(value, instance)); > } else { > super.appendDetail(buffer, fieldName, value); > } > } > @Override > public void appendDetail(final StringBuffer buffer, final String fieldName, final Collection value) { > appendDetail(buffer, fieldName, value.toArray()); > } > } > ====================================== > When I use my custom MyStyle: > String s = ReflectionToStringBuilder.toString(a, MyStyle.getInstance()); > System.out.println(s); > The output is: > A@3ea981ca[p1=0, p2=, b=byte@1ee7b241[p4=234]] > So, the name of the class 'B' is not displayed. > I expected something like: b=B@1ee7b241[p4=234] > Instead, the name of the class 'B' is replaced with 'byte'. > I don't know why. -- This message is automatically generated by JIRA. If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa For more information on JIRA, see: http://www.atlassian.com/software/jira