You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by se...@apache.org on 2009/03/27 22:37:15 UTC

svn commit: r759359 - /commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/Simple8BitZipEncoding.java

Author: sebb
Date: Fri Mar 27 21:37:14 2009
New Revision: 759359

URL: http://svn.apache.org/viewvc?rev=759359&view=rev
Log:
Class was not thread-safe:
- external byte array was stored directly
- List was created and then modified via the final variable
Fixed by copying byte array and storing List once as unmodifiable List

Modified:
    commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/Simple8BitZipEncoding.java

Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/Simple8BitZipEncoding.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/Simple8BitZipEncoding.java?rev=759359&r1=759358&r2=759359&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/Simple8BitZipEncoding.java (original)
+++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/Simple8BitZipEncoding.java Fri Mar 27 21:37:14 2009
@@ -42,6 +42,7 @@
  * implementation, Cp437 and Cp850.</p>
  * 
  * <p>The methods of this class are reentrant.</p>
+ * @Immutable
  */
 class Simple8BitZipEncoding implements ZipEncoding {
 
@@ -88,17 +89,17 @@
      * stored as an array of 128 chars.
      */
     public Simple8BitZipEncoding(char[] highChars) {
-        this.highChars = highChars;
-        this.reverseMapping = new ArrayList(this.highChars.length);
+        this.highChars = (char[]) highChars.clone();
+        List temp = new ArrayList(this.highChars.length);
 
         byte code = 127;
 
         for (int i = 0; i < this.highChars.length; ++i) {
-            this.reverseMapping.add(new Simple8BitChar(++code,
-                                                       this.highChars[i]));
+            temp.add(new Simple8BitChar(++code, this.highChars[i]));
         }
 
-        Collections.sort(this.reverseMapping);
+        Collections.sort(temp);
+        this.reverseMapping = Collections.unmodifiableList(temp);
     }
 
     /**