commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject [1/5] commons-compress git commit: implement clone the way it is supposed to
Date Thu, 06 Jul 2017 07:53:54 GMT
Repository: commons-compress
Updated Branches:
  refs/heads/master d5c4ab74a -> b4445543d


implement clone the way it is supposed to

yes, `Cloneable` is broken, I know.

`AsiExtraField` is not final, so in theory subclasses may exist that
override `clone`. By not calling `super.clone()` we would no longer
populate the subclass' fields properly.


Project: http://git-wip-us.apache.org/repos/asf/commons-compress/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-compress/commit/10dbea13
Tree: http://git-wip-us.apache.org/repos/asf/commons-compress/tree/10dbea13
Diff: http://git-wip-us.apache.org/repos/asf/commons-compress/diff/10dbea13

Branch: refs/heads/master
Commit: 10dbea13f4da599af0032dbd77ac7ef9bf047b45
Parents: d5c4ab7
Author: Stefan Bodewig <bodewig@apache.org>
Authored: Thu Jul 6 09:34:06 2017 +0200
Committer: Stefan Bodewig <bodewig@apache.org>
Committed: Thu Jul 6 09:34:06 2017 +0200

----------------------------------------------------------------------
 .../compress/archivers/zip/AsiExtraField.java       | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-compress/blob/10dbea13/src/main/java/org/apache/commons/compress/archivers/zip/AsiExtraField.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/compress/archivers/zip/AsiExtraField.java b/src/main/java/org/apache/commons/compress/archivers/zip/AsiExtraField.java
index 4d8b65c..e4afa95 100644
--- a/src/main/java/org/apache/commons/compress/archivers/zip/AsiExtraField.java
+++ b/src/main/java/org/apache/commons/compress/archivers/zip/AsiExtraField.java
@@ -325,13 +325,13 @@ public class AsiExtraField implements ZipExtraField, UnixStat, Cloneable
{
 
     @Override
     public Object clone() {
-        AsiExtraField cloned = new AsiExtraField();
-        cloned.mode = mode;
-        cloned.uid = uid;
-        cloned.gid =gid;
-        cloned.link = link;
-        cloned.dirFlag = dirFlag;
-        cloned.crc = new CRC32();
-        return cloned;
+        try {
+            final AsiExtraField cloned = (AsiExtraField) super.clone();
+            cloned.crc = new CRC32();
+            return cloned;
+        } catch (final CloneNotSupportedException cnfe) {
+            // impossible
+            throw new RuntimeException(cnfe); //NOSONAR
+        }
     }
 }


Mime
View raw message