summaryrefslogtreecommitdiffstats
path: root/luni
diff options
context:
space:
mode:
authorNarayan Kamath <narayan@google.com>2015-04-16 10:02:55 +0000
committerAndroid Git Automerger <android-git-automerger@android.com>2015-04-16 10:02:55 +0000
commit5497a9dfe805f4e71a8764f4707e77b20f539fc3 (patch)
treebf4bbd59de9da606a87d832b8e966d326f8d928a /luni
parentb7592c5fe1c7048082db172f1a28c6330adf08da (diff)
parent4b915681b32df299c93c2cd0a9911deba0ecdebd (diff)
downloadlibcore-5497a9dfe805f4e71a8764f4707e77b20f539fc3.zip
libcore-5497a9dfe805f4e71a8764f4707e77b20f539fc3.tar.gz
libcore-5497a9dfe805f4e71a8764f4707e77b20f539fc3.tar.bz2
am 4b915681: am 81347df7: Merge "Make Manifest#clone obey clone\'s contract."
* commit '4b915681b32df299c93c2cd0a9911deba0ecdebd': Make Manifest#clone obey clone's contract.
Diffstat (limited to 'luni')
-rw-r--r--luni/src/main/java/java/util/jar/Manifest.java26
1 files changed, 20 insertions, 6 deletions
diff --git a/luni/src/main/java/java/util/jar/Manifest.java b/luni/src/main/java/java/util/jar/Manifest.java
index 6a3936d..5a6b42d 100644
--- a/luni/src/main/java/java/util/jar/Manifest.java
+++ b/luni/src/main/java/java/util/jar/Manifest.java
@@ -41,8 +41,10 @@ public class Manifest implements Cloneable {
private static final byte[] VALUE_SEPARATOR = new byte[] { ':', ' ' };
- private final Attributes mainAttributes;
- private final HashMap<String, Attributes> entries;
+ /* non-final for {@code #clone()} */
+ private Attributes mainAttributes;
+ /* non-final for {@code #clone()} */
+ private HashMap<String, Attributes> entries;
static final class Chunk {
final int start;
@@ -93,9 +95,7 @@ public class Manifest implements Cloneable {
*/
@SuppressWarnings("unchecked")
public Manifest(Manifest man) {
- mainAttributes = (Attributes) man.mainAttributes.clone();
- entries = (HashMap<String, Attributes>) ((HashMap<String, Attributes>) man
- .getEntries()).clone();
+ cloneAttributesAndEntriesFrom(man);
}
Manifest(byte[] manifestBytes, boolean readChunks) throws IOException {
@@ -156,7 +156,21 @@ public class Manifest implements Cloneable {
*/
@Override
public Object clone() {
- return new Manifest(this);
+ Manifest result;
+ try {
+ result = (Manifest) super.clone();
+ } catch (CloneNotSupportedException e) {
+ throw new AssertionError(e);
+ }
+
+ result.cloneAttributesAndEntriesFrom(this);
+ return result;
+ }
+
+ private final void cloneAttributesAndEntriesFrom(Manifest other) {
+ mainAttributes = (Attributes) other.mainAttributes.clone();
+ entries = (HashMap<String, Attributes>) ((HashMap<String, Attributes>) other
+ .getEntries()).clone();
}
/**