diff --git a/aws/s3/core/src/main/java/org/jclouds/aws/s3/domain/S3Object.java b/aws/s3/core/src/main/java/org/jclouds/aws/s3/domain/S3Object.java index 2b0caf867e..7d5ee147ee 100644 --- a/aws/s3/core/src/main/java/org/jclouds/aws/s3/domain/S3Object.java +++ b/aws/s3/core/src/main/java/org/jclouds/aws/s3/domain/S3Object.java @@ -216,14 +216,21 @@ public class S3Object { } public void setMd5(byte[] md5) { - this.md5 = Arrays.copyOf(md5, md5.length); + this.md5 = new byte[md5.length]; + System.arraycopy(md5, 0, this.md5, 0, md5.length); } /** * @return the md5 value stored in the Etag header returned by S3. */ public byte[] getMd5() { - return (md5 == null) ? null : Arrays.copyOf(md5, md5.length); + if (md5 != null) { + byte[] retval = new byte[md5.length]; + System.arraycopy(this.md5, 0, retval, 0, md5.length); + return retval; + } else { + return null; + } } public void setUserMetadata(Multimap userMetadata) { diff --git a/aws/s3/core/src/test/java/org/jclouds/aws/s3/domain/S3ObjectTest.java b/aws/s3/core/src/test/java/org/jclouds/aws/s3/domain/S3ObjectTest.java index 9cfc69254b..128eaed87e 100644 --- a/aws/s3/core/src/test/java/org/jclouds/aws/s3/domain/S3ObjectTest.java +++ b/aws/s3/core/src/test/java/org/jclouds/aws/s3/domain/S3ObjectTest.java @@ -25,6 +25,7 @@ package org.jclouds.aws.s3.domain; import org.jclouds.http.ContentTypes; import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotSame; import org.testng.annotations.Test; import java.io.File; @@ -40,4 +41,14 @@ public class S3ObjectTest { assertEquals(object.getMetadata().getContentType(), ContentTypes.BINARY); } + + @Test + void testMd5CopyingNotReference() { + byte[] md5 = new byte[12]; + S3Object object = new S3Object("test"); + object.getMetadata().setMd5(md5); + byte[] returnedMd5 = object.getMetadata().getMd5(); + assertNotSame(md5, returnedMd5); + } + }