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 BA47A9953 for ; Fri, 9 Mar 2012 16:45:21 +0000 (UTC) Received: (qmail 46766 invoked by uid 500); 9 Mar 2012 16:45:21 -0000 Delivered-To: apmail-commons-issues-archive@commons.apache.org Received: (qmail 46680 invoked by uid 500); 9 Mar 2012 16:45:21 -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 46671 invoked by uid 99); 9 Mar 2012 16:45:21 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 09 Mar 2012 16:45:21 +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; Fri, 09 Mar 2012 16:45:18 +0000 Received: from hel.zones.apache.org (hel.zones.apache.org [140.211.11.116]) by hel.zones.apache.org (Postfix) with ESMTP id BEF5216ED3 for ; Fri, 9 Mar 2012 16:44:57 +0000 (UTC) Date: Fri, 9 Mar 2012 16:44:57 +0000 (UTC) From: "Emmanuel Bourg (Commented) (JIRA)" To: issues@commons.apache.org Message-ID: <325469586.43945.1331311497784.JavaMail.tomcat@hel.zones.apache.org> In-Reply-To: <205003566.29470.1331066518153.JavaMail.tomcat@hel.zones.apache.org> Subject: [jira] [Commented] (SANDBOX-408) CSVFormat describes itself as immutable, but it is not - in particular it is not thread-safe 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/SANDBOX-408?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13226187#comment-13226187 ] Emmanuel Bourg commented on SANDBOX-408: ---------------------------------------- After checking the JLS and the excellent Java Concurrency In Practice I now understand why my analysis is wrong. CSVFormat is "effectively immutable" but must be safely published to avoid visibility issues. I made the fields volatile to ensure the thread safety. I prefer this to the constructor idiom which is less readable with a large number of fields. Also I expect some fields to be added or removed in the near future, the clone construct will be easier to maintain. I don't mind switching to constructors later when the API is stabilized. Thank you for pointing to this issue Sebb, that was very instructing. > CSVFormat describes itself as immutable, but it is not - in particular it is not thread-safe > -------------------------------------------------------------------------------------------- > > Key: SANDBOX-408 > URL: https://issues.apache.org/jira/browse/SANDBOX-408 > Project: Commons Sandbox > Issue Type: Bug > Components: CSV > Reporter: Sebb > Attachments: CSVFormat.java > > > CSVFormat describes itself as immutable, but it is not @Immutable - the class fields are all mutable. > The methods that change the fields do so by creating a clone, and returning the changed clone. > So in a sense the class is immutable. > However, the normal expectation is that @Immutable classes are @ThreadSafe. > CSVFormat is not thread-safe, because the fields are not volatile, and the fields are not written & read using a common lock. > The comment needs to be clarified or removed. -- 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