Return-Path:
X-Original-To: apmail-commons-commits-archive@minotaur.apache.org
Delivered-To: apmail-commons-commits-archive@minotaur.apache.org
Received: from mail.apache.org (hermes.apache.org [140.211.11.3])
by minotaur.apache.org (Postfix) with SMTP id 62A6D9C19
for ;
Thu, 10 Nov 2011 06:15:07 +0000 (UTC)
Received: (qmail 13609 invoked by uid 500); 10 Nov 2011 06:15:06 -0000
Delivered-To: apmail-commons-commits-archive@commons.apache.org
Received: (qmail 13393 invoked by uid 500); 10 Nov 2011 06:15:00 -0000
Mailing-List: contact commits-help@commons.apache.org; run by ezmlm
Precedence: bulk
List-Help:
List-Unsubscribe:
List-Post:
List-Id:
Reply-To: dev@commons.apache.org
Delivered-To: mailing list commits@commons.apache.org
Received: (qmail 13379 invoked by uid 99); 10 Nov 2011 06:14:58 -0000
Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230)
by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 10 Nov 2011 06:14:58 +0000
X-ASF-Spam-Status: No, hits=-2000.0 required=5.0
tests=ALL_TRUSTED
X-Spam-Check-By: apache.org
Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4)
by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 10 Nov 2011 06:14:55 +0000
Received: from eris.apache.org (localhost [127.0.0.1])
by eris.apache.org (Postfix) with ESMTP id 1EAAD2388A5E
for ; Thu, 10 Nov 2011 06:14:34 +0000 (UTC)
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Subject: svn commit: r1200177 -
/commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/builder/ReflectionToStringBuilder.java
Date: Thu, 10 Nov 2011 06:14:34 -0000
To: commits@commons.apache.org
From: ggregory@apache.org
X-Mailer: svnmailer-1.0.8-patched
Message-Id: <20111110061434.1EAAD2388A5E@eris.apache.org>
X-Virus-Checked: Checked by ClamAV on apache.org
Author: ggregory
Date: Thu Nov 10 06:14:33 2011
New Revision: 1200177
URL: http://svn.apache.org/viewvc?rev=1200177&view=rev
Log:
[LANG-762] Handle or document ReflectionToStringBuilder and ToStringBuilder for collections that are not thread safe. Better Javadocs. See Phil's comments in the Jira.
Modified:
commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/builder/ReflectionToStringBuilder.java
Modified: commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/builder/ReflectionToStringBuilder.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/builder/ReflectionToStringBuilder.java?rev=1200177&r1=1200176&r2=1200177&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/builder/ReflectionToStringBuilder.java (original)
+++ commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/builder/ReflectionToStringBuilder.java Thu Nov 10 06:14:33 2011
@@ -32,34 +32,33 @@ import org.apache.commons.lang3.ClassUti
*
* Assists in implementing {@link Object#toString()} methods using reflection.
*
- *
*
* This class uses reflection to determine the fields to append. Because these fields are usually private, the class
* uses {@link java.lang.reflect.AccessibleObject#setAccessible(java.lang.reflect.AccessibleObject[], boolean)} to
* change the visibility of the fields. This will fail under a security manager, unless the appropriate permissions are
* set up correctly.
*
- *
+ *
+ * Using reflection to access (private) fields circumvents any synchronization protection guarding access to these
+ * fields. If a toString method cannot safely read a field, you should exclude it from the toString method, or use
+ * synchronization consistent with the class' lock management around the invocation of the method. Take special care to
+ * exclude non-thread-safe collection classes, because these classes may throw ConcurrentModificationException if
+ * modified while the toString method is executing.
+ *
*
* A typical invocation for this method would look like:
*
- *
*
* public String toString() {
- * return ReflectionToStringBuilder.toString(this);
- * }
- *
- *
- *
+ * return ReflectionToStringBuilder.toString(this);
+ * }
+ *
*
* You can also use the builder to debug 3rd party objects:
*
- *
*
- * System.out.println("An object: " + ReflectionToStringBuilder.toString(anObject));
- *
- *
- *
+ * System.out.println("An object: " + ReflectionToStringBuilder.toString(anObject));
+ *
*
* A subclass can control field output by overriding the methods:
*
@@ -68,26 +67,21 @@ import org.apache.commons.lang3.ClassUti
*
*
*
- * For example, this method does not include the password
field in the returned
- * String
:
+ * For example, this method does not include the password
field in the returned String
:
*
- *
*
* public String toString() {
* return (new ReflectionToStringBuilder(this) {
* protected boolean accept(Field f) {
- * return super.accept(f) && !f.getName().equals("password");
+ * return super.accept(f) && !f.getName().equals("password");
* }
* }).toString();
- * }
- *
- *
- *
+ * }
+ *
*
- * The exact format of the toString
is determined by the {@link ToStringStyle} passed into the
- * constructor.
+ * The exact format of the toString
is determined by the {@link ToStringStyle} passed into the constructor.
*
- *
+ *
* @since 2.0
* @version $Id$
*/