Return-Path: Delivered-To: apmail-commons-issues-archive@minotaur.apache.org Received: (qmail 55497 invoked from network); 26 Feb 2010 08:38:51 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 26 Feb 2010 08:38:51 -0000 Received: (qmail 35152 invoked by uid 500); 26 Feb 2010 08:38:51 -0000 Delivered-To: apmail-commons-issues-archive@commons.apache.org Received: (qmail 35093 invoked by uid 500); 26 Feb 2010 08:38:51 -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 35085 invoked by uid 99); 26 Feb 2010 08:38:51 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 26 Feb 2010 08:38:51 +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.140] (HELO brutus.apache.org) (140.211.11.140) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 26 Feb 2010 08:38:49 +0000 Received: from brutus.apache.org (localhost [127.0.0.1]) by brutus.apache.org (Postfix) with ESMTP id 52E78234C48C for ; Fri, 26 Feb 2010 00:38:28 -0800 (PST) Message-ID: <1548971420.549921267173508338.JavaMail.jira@brutus.apache.org> Date: Fri, 26 Feb 2010 08:38:28 +0000 (UTC) From: "Jochen Wiedmann (JIRA)" To: issues@commons.apache.org Subject: [jira] Commented: (CODEC-96) Base64 encode() method is no longer thread-safe, breaking clients using it as a shared BinaryEncoder In-Reply-To: <286014533.546751267160427969.JavaMail.jira@brutus.apache.org> 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/CODEC-96?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12838758#action_12838758 ] Jochen Wiedmann commented on CODEC-96: -------------------------------------- The problem is not in the Base64 code, but in your example. Of course, you must create a new Base64 instance whenever you use it. But that's not a problem, creating an encoder is cheap. class Example { byte[] someMethod(byte[] data) { try { return new Base64().encode(data); } catch (EncoderException e) { throw new RuntimeException(e); } } } > Base64 encode() method is no longer thread-safe, breaking clients using it as a shared BinaryEncoder > ---------------------------------------------------------------------------------------------------- > > Key: CODEC-96 > URL: https://issues.apache.org/jira/browse/CODEC-96 > Project: Commons Codec > Issue Type: Bug > Affects Versions: 1.4 > Reporter: Matt Ryall > > Streaming support was added to Base64 in commons-codec 1.4 with CODEC-69. This introduced instance variables to Base64 which means the class can no longer be used as a shared BinaryEncoder instance. > For example, BinaryEncoder has an interface which could be (and was) used like this with Base64: > {code:java} > class Example { > private BinaryEncoder encoder = new Base64(); > byte[] someMethod(byte[] data) { > try { > return encoder.encode(data); > } > catch (EncoderException e) { > throw new RuntimeException(e); > } > } > } > {code} > Base64 is no longer thread-safe in commons-codec 1.4, so code like the above which is accessed by multiple threads can throw NullPointerException: > {noformat} > java.lang.NullPointerException > at org.apache.commons.codec.binary.Base64.encode(Base64.java:469) > at org.apache.commons.codec.binary.Base64.encode(Base64.java:937) > at ... (application code) > {noformat} > Looking at the implementation of Base64, I think making it thread-safe for this kind of usage would be quite tricky. I haven't attempted to prepare a patch. > I would be happy if it was indicated in the Javadoc that Base64 is not thread-safe and should not be shared. However, some other users of commons-codec might be more worried about this regression. -- This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online.