Skip to content

Commit

Permalink
Merge pull request Azure#396 from seanmcc-msft/mutableDefaultTypes2
Browse files Browse the repository at this point in the history
Removed DEFAULT and NONE static variables, Created empty constructors…
  • Loading branch information
rickle-msft authored Oct 31, 2018
2 parents 4b72963 + f65b3ee commit c21d854
Show file tree
Hide file tree
Showing 32 changed files with 87 additions and 129 deletions.
1 change: 1 addition & 0 deletions BreakingChanges.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
XXXX.XX.XX Version XX.X.X
* HTTPGetterInfo was made an internal type as it is an internal implementation detail.
* DownloadResponse constructor was made internal as there is no need for customers to construct their own responses; all HTTP responses should be generated internally.
* Removed DEFAULT and NONE static variables. Empty constructors should be used instead. DEFAULT static values were error prone and unsafe to use because although the field was final, the objects were mutable, so it was possible the value could be changed accidentally and alter the behavior of the program.

2018.08.11 Version 10.1.0
* Interfaces for helper types updated to be more consistent throughout the library. All types, with the exception of the options for pipeline factories, use a fluent pattern.
Expand Down
1 change: 1 addition & 0 deletions ChangeLog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ XXXX.XX.XX Version XX.X.X
* Added CopyFromURL, which will do a synchronous server-side copy, meaning the service will not return an HTTP response until it has completed the copy.
* HTTPGetterInfo was made an internal type as it is an internal implementation detail.
* DownloadResponse constructor was made internal as there is no need for customers to construct their own responses; all HTTP responses should be generated internally.
* Removed DEFAULT and NONE static variables. Empty constructors should be used instead. DEFAULT static values were error prone and unsafe to use because although the field was final, the objects were mutable, so it was possible the value could be changed accidentally and alter the behavior of the program.

2018.09.11 Version 10.1.0
* Interfaces for helper types updated to be more consistent throughout the library. All types, with the exception of the options for pipeline factories, use a fluent pattern.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ private String stringToSign(final SharedKeyCredentials sharedKeyCredentials) {
resourceTypes,
this.startTime == null ? "" : Utility.ISO8601UTCDateFormatter.format(this.startTime),
Utility.ISO8601UTCDateFormatter.format(this.expiryTime),
this.ipRange == null ? IPRange.DEFAULT.toString() : this.ipRange.toString(),
this.ipRange == null ? (new IPRange()).toString() : this.ipRange.toString(),
this.protocol == null ? "" : this.protocol.toString(),
this.version,
Constants.EMPTY_STRING // Account SAS requires an additional newline character
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,6 @@
*/
public final class AppendBlobAccessConditions {

/**
* An object representing no access conditions.
*/
public static final AppendBlobAccessConditions NONE =
new AppendBlobAccessConditions();

private AppendPositionAccessConditions appendPositionAccessConditions;

private ModifiedAccessConditions modifiedAccessConditions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ public Single<AppendBlobCreateResponse> create() {
*/
public Single<AppendBlobCreateResponse> create(BlobHTTPHeaders headers, Metadata metadata,
BlobAccessConditions accessConditions, Context context) {
metadata = metadata == null ? Metadata.NONE : metadata;
accessConditions = accessConditions == null ? BlobAccessConditions.NONE : accessConditions;
metadata = metadata == null ? new Metadata() : metadata;
accessConditions = accessConditions == null ? new BlobAccessConditions() : accessConditions;
context = context == null ? Context.NONE : context;

return addErrorWrappingToSingle(this.storageClient.generatedAppendBlobs().createWithRestResponseAsync(context,
Expand Down Expand Up @@ -195,10 +195,10 @@ public Single<AppendBlobAppendBlockResponse> appendBlock(Flowable<ByteBuffer> da
*/
public Single<AppendBlobAppendBlockResponse> appendBlock(Flowable<ByteBuffer> data, long length,
AppendBlobAccessConditions appendBlobAccessConditions, Context context) {
appendBlobAccessConditions = appendBlobAccessConditions == null ? AppendBlobAccessConditions.NONE :
appendBlobAccessConditions = appendBlobAccessConditions == null ? new AppendBlobAccessConditions() :
appendBlobAccessConditions;
appendBlobAccessConditions = appendBlobAccessConditions == null
? AppendBlobAccessConditions.NONE : appendBlobAccessConditions;
? new AppendBlobAccessConditions() : appendBlobAccessConditions;
context = context == null ? Context.NONE : context;

return addErrorWrappingToSingle(this.storageClient.generatedAppendBlobs().appendBlockWithRestResponseAsync(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@
*/
public final class BlobAccessConditions {

public static final BlobAccessConditions NONE =
new BlobAccessConditions();

private ModifiedAccessConditions modifiedAccessConditions;

private LeaseAccessConditions leaseAccessConditions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,6 @@
*/
public final class BlobListingDetails {

/**
* An object representing no listing details.
*/
public static final BlobListingDetails NONE = new BlobListingDetails();

private boolean copy;

private boolean metadata;
Expand Down
5 changes: 0 additions & 5 deletions src/main/java/com/microsoft/azure/storage/blob/BlobRange.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@
*/
public final class BlobRange {

/**
* An object which reflects the service's default range, which is the whole blob.
*/
public static final BlobRange DEFAULT = new BlobRange();

private long offset;

private Long count;
Expand Down
26 changes: 13 additions & 13 deletions src/main/java/com/microsoft/azure/storage/blob/BlobURL.java
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,10 @@ public Single<BlobStartCopyFromURLResponse> startCopyFromURL(URL sourceURL) {
public Single<BlobStartCopyFromURLResponse> startCopyFromURL(URL sourceURL, Metadata metadata,
ModifiedAccessConditions sourceModifiedAccessConditions, BlobAccessConditions destAccessConditions,
Context context) {
metadata = metadata == null ? Metadata.NONE : metadata;
metadata = metadata == null ? new Metadata() : metadata;
sourceModifiedAccessConditions = sourceModifiedAccessConditions == null ?
new ModifiedAccessConditions() : sourceModifiedAccessConditions;
destAccessConditions = destAccessConditions == null ? BlobAccessConditions.NONE : destAccessConditions;
destAccessConditions = destAccessConditions == null ? new BlobAccessConditions() : destAccessConditions;
context = context == null ? Context.NONE : context;

// We want to hide the SourceAccessConditions type from the user for consistency's sake, so we convert here.
Expand Down Expand Up @@ -288,10 +288,10 @@ public Single<BlobCopyFromURLResponse> syncCopyFromURL(URL copySource) {
public Single<BlobCopyFromURLResponse> syncCopyFromURL(URL copySource, Metadata metadata,
ModifiedAccessConditions sourceModifiedAccessConditions, BlobAccessConditions destAccessConditions,
Context context) {
metadata = metadata == null ? Metadata.NONE : metadata;
metadata = metadata == null ? new Metadata() : metadata;
sourceModifiedAccessConditions = sourceModifiedAccessConditions == null ?
new ModifiedAccessConditions() : sourceModifiedAccessConditions;
destAccessConditions = destAccessConditions == null ? BlobAccessConditions.NONE : destAccessConditions;
destAccessConditions = destAccessConditions == null ? new BlobAccessConditions() : destAccessConditions;
context = context == null ? Context.NONE : context;

// We want to hide the SourceAccessConditions type from the user for consistency's sake, so we convert here.
Expand Down Expand Up @@ -371,8 +371,8 @@ public Single<DownloadResponse> download(BlobRange range) {
public Single<DownloadResponse> download(BlobRange range, BlobAccessConditions accessConditions,
boolean rangeGetContentMD5, Context context) {
Boolean getMD5 = rangeGetContentMD5 ? rangeGetContentMD5 : null;
range = range == null ? BlobRange.DEFAULT : range;
accessConditions = accessConditions == null ? BlobAccessConditions.NONE : accessConditions;
range = range == null ? new BlobRange() : range;
accessConditions = accessConditions == null ? new BlobAccessConditions() : accessConditions;
HTTPGetterInfo info = new HTTPGetterInfo()
.withCount(range.offset())
.withCount(range.count())
Expand Down Expand Up @@ -435,7 +435,7 @@ public Single<BlobDeleteResponse> delete() {
*/
public Single<BlobDeleteResponse> delete(DeleteSnapshotsOptionType deleteBlobSnapshotOptions,
BlobAccessConditions accessConditions, Context context) {
accessConditions = accessConditions == null ? BlobAccessConditions.NONE : accessConditions;
accessConditions = accessConditions == null ? new BlobAccessConditions() : accessConditions;
context = context == null ? Context.NONE : context;

return addErrorWrappingToSingle(this.storageClient.generatedBlobs().deleteWithRestResponseAsync(
Expand Down Expand Up @@ -476,7 +476,7 @@ public Single<BlobGetPropertiesResponse> getProperties() {
* For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java)
*/
public Single<BlobGetPropertiesResponse> getProperties(BlobAccessConditions accessConditions, Context context) {
accessConditions = accessConditions == null ? BlobAccessConditions.NONE : accessConditions;
accessConditions = accessConditions == null ? new BlobAccessConditions() : accessConditions;
context = context == null ? Context.NONE : context;

return addErrorWrappingToSingle(this.storageClient.generatedBlobs().getPropertiesWithRestResponseAsync(
Expand Down Expand Up @@ -523,7 +523,7 @@ public Single<BlobSetHTTPHeadersResponse> setHTTPHeaders(BlobHTTPHeaders headers
*/
public Single<BlobSetHTTPHeadersResponse> setHTTPHeaders(BlobHTTPHeaders headers,
BlobAccessConditions accessConditions, Context context) {
accessConditions = accessConditions == null ? BlobAccessConditions.NONE : accessConditions;
accessConditions = accessConditions == null ? new BlobAccessConditions() : accessConditions;
context = context == null ? Context.NONE : context;

return addErrorWrappingToSingle(this.storageClient.generatedBlobs().setHTTPHeadersWithRestResponseAsync(
Expand Down Expand Up @@ -569,8 +569,8 @@ public Single<BlobSetMetadataResponse> setMetadata(Metadata metadata) {
*/
public Single<BlobSetMetadataResponse> setMetadata(Metadata metadata, BlobAccessConditions accessConditions,
Context context) {
metadata = metadata == null ? Metadata.NONE : metadata;
accessConditions = accessConditions == null ? BlobAccessConditions.NONE : accessConditions;
metadata = metadata == null ? new Metadata() : metadata;
accessConditions = accessConditions == null ? new BlobAccessConditions() : accessConditions;
context = context == null ? Context.NONE : context;

return addErrorWrappingToSingle(this.storageClient.generatedBlobs().setMetadataWithRestResponseAsync(
Expand Down Expand Up @@ -613,8 +613,8 @@ public Single<BlobCreateSnapshotResponse> createSnapshot() {
*/
public Single<BlobCreateSnapshotResponse> createSnapshot(Metadata metadata, BlobAccessConditions accessConditions,
Context context) {
metadata = metadata == null ? Metadata.NONE : metadata;
accessConditions = accessConditions == null ? BlobAccessConditions.NONE : accessConditions;
metadata = metadata == null ? new Metadata() : metadata;
accessConditions = accessConditions == null ? new BlobAccessConditions() : accessConditions;
context = context == null ? Context.NONE : context;

return addErrorWrappingToSingle(this.storageClient.generatedBlobs().createSnapshotWithRestResponseAsync(
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/com/microsoft/azure/storage/blob/BlockBlobURL.java
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@ public Single<BlockBlobUploadResponse> upload(Flowable<ByteBuffer> data, long le
*/
public Single<BlockBlobUploadResponse> upload(Flowable<ByteBuffer> data, long length, BlobHTTPHeaders headers,
Metadata metadata, BlobAccessConditions accessConditions, Context context) {
metadata = metadata == null ? Metadata.NONE : metadata;
accessConditions = accessConditions == null ? BlobAccessConditions.NONE : accessConditions;
metadata = metadata == null ? new Metadata() : metadata;
accessConditions = accessConditions == null ? new BlobAccessConditions() : accessConditions;
context = context == null ? Context.NONE : context;

return addErrorWrappingToSingle(this.storageClient.generatedBlockBlobs().uploadWithRestResponseAsync(context,
Expand Down Expand Up @@ -307,7 +307,7 @@ public Single<BlockBlobStageBlockFromURLResponse> stageBlockFromURL(String base6
public Single<BlockBlobStageBlockFromURLResponse> stageBlockFromURL(String base64BlockID, URL sourceURL,
BlobRange sourceRange, byte[] sourceContentMD5, LeaseAccessConditions leaseAccessConditions,
Context context) {
sourceRange = sourceRange == null ? BlobRange.DEFAULT : sourceRange;
sourceRange = sourceRange == null ? new BlobRange() : sourceRange;
context = context == null ? Context.NONE : context;

return addErrorWrappingToSingle(
Expand Down Expand Up @@ -423,8 +423,8 @@ public Single<BlockBlobCommitBlockListResponse> commitBlockList(List<String> bas
*/
public Single<BlockBlobCommitBlockListResponse> commitBlockList(List<String> base64BlockIDs,
BlobHTTPHeaders headers, Metadata metadata, BlobAccessConditions accessConditions, Context context) {
metadata = metadata == null ? Metadata.NONE : metadata;
accessConditions = accessConditions == null ? BlobAccessConditions.NONE : accessConditions;
metadata = metadata == null ? new Metadata() : metadata;
accessConditions = accessConditions == null ? new BlobAccessConditions() : accessConditions;
context = context == null ? Context.NONE : context;

return addErrorWrappingToSingle(this.storageClient.generatedBlockBlobs().commitBlockListWithRestResponseAsync(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,6 @@
*/
public final class ContainerAccessConditions {

/**
* An object representing no access conditions.
*/
public static final ContainerAccessConditions NONE = new ContainerAccessConditions();

private ModifiedAccessConditions modifiedAccessConditions;

private LeaseAccessConditions leaseAccessConditions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,6 @@
*/
public final class ContainerListingDetails {

/**
* An object indicating that no extra details should be returned.
*/
public static final ContainerListingDetails NONE = new ContainerListingDetails();

private boolean metadata;

public ContainerListingDetails() {
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/com/microsoft/azure/storage/blob/ContainerURL.java
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ public Single<ContainerCreateResponse> create() {
* For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java)
*/
public Single<ContainerCreateResponse> create(Metadata metadata, PublicAccessType accessType, Context context) {
metadata = metadata == null ? Metadata.NONE : metadata;
metadata = metadata == null ? new Metadata() : metadata;
context = context == null ? Context.NONE : context;

return addErrorWrappingToSingle(this.storageClient.generatedContainers().createWithRestResponseAsync(
Expand Down Expand Up @@ -246,7 +246,7 @@ public Single<ContainerDeleteResponse> delete() {
* For more samples, please see the [Samples file](%https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java)
*/
public Single<ContainerDeleteResponse> delete(ContainerAccessConditions accessConditions, Context context) {
accessConditions = accessConditions == null ? ContainerAccessConditions.NONE : accessConditions;
accessConditions = accessConditions == null ? new ContainerAccessConditions() : accessConditions;
context = context == null ? Context.NONE : context;

if (!validateNoEtag(accessConditions.modifiedAccessConditions())) {
Expand Down Expand Up @@ -342,8 +342,8 @@ public Single<ContainerSetMetadataResponse> setMetadata(Metadata metadata) {
*/
public Single<ContainerSetMetadataResponse> setMetadata(Metadata metadata,
ContainerAccessConditions accessConditions, Context context) {
metadata = metadata == null ? Metadata.NONE : metadata;
accessConditions = accessConditions == null ? ContainerAccessConditions.NONE : accessConditions;
metadata = metadata == null ? new Metadata() : metadata;
accessConditions = accessConditions == null ? new ContainerAccessConditions() : accessConditions;
context = context == null ? Context.NONE : context;
if (!validateNoEtag(accessConditions.modifiedAccessConditions()) ||
accessConditions.modifiedAccessConditions().ifUnmodifiedSince() != null) {
Expand Down Expand Up @@ -457,7 +457,7 @@ public Single<ContainerSetAccessPolicyResponse> setAccessPolicy(PublicAccessType
*/
public Single<ContainerSetAccessPolicyResponse> setAccessPolicy(PublicAccessType accessType,
List<SignedIdentifier> identifiers, ContainerAccessConditions accessConditions, Context context) {
accessConditions = accessConditions == null ? ContainerAccessConditions.NONE : accessConditions;
accessConditions = accessConditions == null ? new ContainerAccessConditions() : accessConditions;
context = context == null ? Context.NONE : context;

if (!validateNoEtag(accessConditions.modifiedAccessConditions())) {
Expand Down Expand Up @@ -839,7 +839,7 @@ public Single<ContainerListBlobFlatSegmentResponse> listBlobsFlatSegment(String
*/
public Single<ContainerListBlobFlatSegmentResponse> listBlobsFlatSegment(String marker, ListBlobsOptions options,
Context context) {
options = options == null ? ListBlobsOptions.DEFAULT : options;
options = options == null ? new ListBlobsOptions() : options;
context = context == null ? Context.NONE : context;

return addErrorWrappingToSingle(this.storageClient.generatedContainers()
Expand Down Expand Up @@ -911,7 +911,7 @@ public Single<ContainerListBlobHierarchySegmentResponse> listBlobsHierarchySegme
*/
public Single<ContainerListBlobHierarchySegmentResponse> listBlobsHierarchySegment(String marker, String delimiter,
ListBlobsOptions options, Context context) {
options = options == null ? ListBlobsOptions.DEFAULT : options;
options = options == null ? new ListBlobsOptions() : options;
if (options.details().snapshots()) {
throw new UnsupportedOperationException("Including snapshots in a hierarchical listing is not supported.");
}
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/com/microsoft/azure/storage/blob/IPRange.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
*/
public final class IPRange {

public static final IPRange DEFAULT = new IPRange();

private String ipMin;

private String ipMax;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,14 @@
*/
public final class ListBlobsOptions {

/**
* An object representing the default options: no details, prefix, or delimiter. Uses the server default for
* maxResults.
*/
public static final ListBlobsOptions DEFAULT = new ListBlobsOptions();

private BlobListingDetails details;

private String prefix;

private Integer maxResults;

public ListBlobsOptions() {
this.details = BlobListingDetails.NONE;
this.details = new BlobListingDetails();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,14 @@
*/
public final class ListContainersOptions {

/**
* An object representing the default options: no details or prefix and using the service's default for maxResults.
*/
public static final ListContainersOptions DEFAULT =
new ListContainersOptions();

private ContainerListingDetails details;

private String prefix;

private Integer maxResults;

public ListContainersOptions() {
this.details = ContainerListingDetails.NONE;
this.details = new ContainerListingDetails();
}

/**
Expand Down
Loading

0 comments on commit c21d854

Please sign in to comment.