Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changing isServerEncrypted parameter to Boolean to avoid NPE #32312

Merged
merged 7 commits into from
Dec 1, 2022
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions sdk/storage/azure-storage-blob/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
--add-opens com.azure.storage.blob/com.azure.storage.blob.implementation.util=ALL-UNNAMED
--add-opens com.azure.storage.blob/com.azure.storage.blob.specialized=ALL-UNNAMED
--add-opens com.azure.storage.blob/com.azure.storage.blob.changefeed=ALL-UNNAMED
--add-opens com.azure.storage.blob/com.azure.storage.blob.implementation.models=ALL-UNNAMED
--add-reads com.azure.core=ALL-UNNAMED
--add-reads com.azure.core.test=ALL-UNNAMED
--add-reads com.azure.core.amqp=ALL-UNNAMED
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,32 @@ public class BlockBlobItem {
* @param contentMd5 Content MD5 of the block blob.
* @param isServerEncrypted Flag indicating if the block blob is encrypted on the server.
* @param encryptionKeySha256 The encryption key used to encrypt the block blob.
* @param encryptionScope The encryption scope used to encrypt the block blob.
* @param versionId The version identifier of the block blob.
*/
public BlockBlobItem(final String eTag, final OffsetDateTime lastModified, final byte[] contentMd5,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

adding this below the constructors instead of above will maintain the chronological progression of these constructors, making it easier to decipher later.

final Boolean isServerEncrypted, final String encryptionKeySha256, final String encryptionScope,
final String versionId) {
this.eTag = eTag;
this.lastModified = lastModified;
this.contentMd5 = CoreUtils.clone(contentMd5);
this.isServerEncrypted = isServerEncrypted;
this.encryptionKeySha256 = encryptionKeySha256;
this.encryptionScope = encryptionScope;
this.versionId = versionId;
}

/**
* Constructs a {@link BlockBlobItem}.
*
* @param eTag ETag of the block blob.
* @param lastModified Last modified time of the block blob.
* @param contentMd5 Content MD5 of the block blob.
* @param isServerEncrypted Flag indicating if the block blob is encrypted on the server.
* @param encryptionKeySha256 The encryption key used to encrypt the block blob.
* @deprecated Use {@link #BlockBlobItem(String, OffsetDateTime, byte[], Boolean, String, String, String)} instead.
*/
@Deprecated
public BlockBlobItem(final String eTag, final OffsetDateTime lastModified, final byte[] contentMd5,
final boolean isServerEncrypted, final String encryptionKeySha256) {
this(eTag, lastModified, contentMd5, isServerEncrypted, encryptionKeySha256, null);
Expand All @@ -44,7 +69,9 @@ public BlockBlobItem(final String eTag, final OffsetDateTime lastModified, final
* @param isServerEncrypted Flag indicating if the block blob is encrypted on the server.
* @param encryptionKeySha256 The encryption key used to encrypt the block blob.
* @param encryptionScope The encryption scope used to encrypt the block blob.
* @deprecated Use {@link #BlockBlobItem(String, OffsetDateTime, byte[], Boolean, String, String, String)} instead.
*/
@Deprecated
public BlockBlobItem(final String eTag, final OffsetDateTime lastModified, final byte[] contentMd5,
final boolean isServerEncrypted, final String encryptionKeySha256, final String encryptionScope) {
this(eTag, lastModified, contentMd5, isServerEncrypted, encryptionKeySha256, encryptionScope, null);
Expand All @@ -60,17 +87,13 @@ public BlockBlobItem(final String eTag, final OffsetDateTime lastModified, final
* @param encryptionKeySha256 The encryption key used to encrypt the block blob.
* @param encryptionScope The encryption scope used to encrypt the block blob.
* @param versionId The version identifier of the block blob.
* @deprecated Use {@link #BlockBlobItem(String, OffsetDateTime, byte[], Boolean, String, String, String)} instead.
*/
@Deprecated
public BlockBlobItem(final String eTag, final OffsetDateTime lastModified, final byte[] contentMd5,
final boolean isServerEncrypted, final String encryptionKeySha256,
final String encryptionScope, final String versionId) {
this.eTag = eTag;
this.lastModified = lastModified;
this.contentMd5 = CoreUtils.clone(contentMd5);
this.isServerEncrypted = isServerEncrypted;
this.encryptionKeySha256 = encryptionKeySha256;
this.encryptionScope = encryptionScope;
this.versionId = versionId;
final boolean isServerEncrypted, final String encryptionKeySha256, final String encryptionScope,
final String versionId) {
this(eTag, lastModified, contentMd5, (Boolean) isServerEncrypted, encryptionKeySha256, encryptionScope, versionId);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package com.azure.storage.blob.specialized

import com.azure.core.exception.UnexpectedLengthException
import com.azure.core.http.HttpHeaders
import com.azure.core.http.HttpMethod
import com.azure.core.http.HttpPipelineCallContext
import com.azure.core.http.HttpPipelineNextPolicy
Expand All @@ -22,13 +23,15 @@ import com.azure.storage.blob.BlobServiceClientBuilder
import com.azure.storage.blob.BlobServiceVersion
import com.azure.storage.blob.BlobUrlParts
import com.azure.storage.blob.ProgressReceiver
import com.azure.storage.blob.implementation.models.BlockBlobsPutBlobFromUrlHeaders
import com.azure.storage.blob.models.AccessTier
import com.azure.storage.blob.models.BlobCopySourceTagsMode
import com.azure.storage.blob.models.BlobErrorCode
import com.azure.storage.blob.models.BlobHttpHeaders
import com.azure.storage.blob.models.BlobRange
import com.azure.storage.blob.models.BlobRequestConditions
import com.azure.storage.blob.models.BlobStorageException
import com.azure.storage.blob.models.BlockBlobItem
import com.azure.storage.blob.models.BlockListType
import com.azure.storage.blob.models.CustomerProvidedKey
import com.azure.storage.blob.models.ParallelTransferOptions
Expand Down Expand Up @@ -2607,4 +2610,28 @@ class BlockBlobAPITest extends APISpec {
BlobCopySourceTagsMode.COPY | _
BlobCopySourceTagsMode.REPLACE | _
}

def "BlockBlobItem null headers"() {
setup:
def headers = new HttpHeaders()
def hd = new BlockBlobsPutBlobFromUrlHeaders(headers)

when:
def blockBlobItem = new BlockBlobItem(hd.getETag(),
hd.getLastModified(),
hd.getContentMD5(),
hd.isXMsRequestServerEncrypted(),
hd.getXMsEncryptionKeySha256(),
hd.getXMsEncryptionScope(),
hd.getXMsVersionId())

then:
blockBlobItem.getETag() == null
blockBlobItem.getLastModified() == null
blockBlobItem.getContentMd5() == null
blockBlobItem.isServerEncrypted() == null
blockBlobItem.getEncryptionKeySha256() == null
blockBlobItem.getEncryptionScope() == null
blockBlobItem.getVersionId() == null
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
{
"networkCallRecords" : [ {
"Method" : "PUT",
"Uri" : "https://REDACTED.blob.core.windows.net/7753539a07753539a653397613a74d390234b40b8bd1?restype=container",
"Headers" : {
"x-ms-version" : "2021-10-04",
"User-Agent" : "azsdk-java-azure-storage-blob/12.21.0-beta.1 (11.0.16.1; Windows 11; 10.0)",
"x-ms-client-request-id" : "d47a9d41-8830-4f02-8bd4-a6a99c504a6e"
},
"Response" : {
"content-length" : "0",
"x-ms-version" : "2021-10-04",
"Server" : "Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0",
"ETag" : "0x8DAD32434A9EF0D",
"Last-Modified" : "Wed, 30 Nov 2022 22:42:48 GMT",
"retry-after" : "0",
"StatusCode" : "201",
"x-ms-request-id" : "7a3dfffc-a01e-002a-790d-05a0a2000000",
"Date" : "Wed, 30 Nov 2022 22:42:47 GMT",
"x-ms-client-request-id" : "d47a9d41-8830-4f02-8bd4-a6a99c504a6e"
},
"Exception" : null
}, {
"Method" : "PUT",
"Uri" : "https://REDACTED.blob.core.windows.net/7753539a07753539a653397613a74d390234b40b8bd1/7753539a17753539a65305102d347f2059158408485c",
"Headers" : {
"x-ms-version" : "2021-10-04",
"User-Agent" : "azsdk-java-azure-storage-blob/12.21.0-beta.1 (11.0.16.1; Windows 11; 10.0)",
"x-ms-client-request-id" : "f9787ccf-1c72-45f7-892d-7e9f0a693da3",
"Content-Type" : "application/octet-stream"
},
"Response" : {
"content-length" : "0",
"x-ms-version" : "2021-10-04",
"Server" : "Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0",
"x-ms-content-crc64" : "6RYQPwaVsyQ=",
"Last-Modified" : "Wed, 30 Nov 2022 22:42:48 GMT",
"x-ms-version-id" : "2022-11-30T22:42:48.4748207Z",
"retry-after" : "0",
"StatusCode" : "201",
"x-ms-request-server-encrypted" : "true",
"Date" : "Wed, 30 Nov 2022 22:42:47 GMT",
"Content-MD5" : "wh+Wm18D0z1D4E+PE252gg==",
"ETag" : "0x8DAD32434D117AF",
"x-ms-request-id" : "7a3e0171-a01e-002a-500d-05a0a2000000",
"x-ms-client-request-id" : "f9787ccf-1c72-45f7-892d-7e9f0a693da3"
},
"Exception" : null
}, {
"Method" : "PUT",
"Uri" : "https://REDACTED.blob.core.windows.net/7753539a07753539a653397613a74d390234b40b8bd1/7753539a27753539a653419280b35f19c474143abbb6",
"Headers" : {
"x-ms-version" : "2021-10-04",
"User-Agent" : "azsdk-java-azure-storage-blob/12.21.0-beta.1 (11.0.16.1; Windows 11; 10.0)",
"x-ms-client-request-id" : "bd083474-97e8-4bf3-85c0-981a4d7d0f38",
"Content-Type" : "application/octet-stream"
},
"Response" : {
"content-length" : "0",
"x-ms-version" : "2021-10-04",
"Server" : "Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0",
"x-ms-content-crc64" : "6RYQPwaVsyQ=",
"Last-Modified" : "Wed, 30 Nov 2022 22:42:48 GMT",
"x-ms-version-id" : "2022-11-30T22:42:48.6337297Z",
"retry-after" : "0",
"StatusCode" : "201",
"x-ms-request-server-encrypted" : "true",
"Date" : "Wed, 30 Nov 2022 22:42:47 GMT",
"Content-MD5" : "wh+Wm18D0z1D4E+PE252gg==",
"ETag" : "0x8DAD32434E95711",
"x-ms-request-id" : "7a3e02a2-a01e-002a-6f0d-05a0a2000000",
"x-ms-client-request-id" : "bd083474-97e8-4bf3-85c0-981a4d7d0f38"
},
"Exception" : null
} ],
"variables" : [ "7753539a07753539a653397613a74d390234b40b8bd1", "7753539a17753539a65305102d347f2059158408485c", "7753539a27753539a653419280b35f19c474143abbb6" ]
}