-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Modified logic for request condition validation to throw after determining all invalid conditions #22532
Modified logic for request condition validation to throw after determining all invalid conditions #22532
Conversation
if (invalidConditions.contains(BlobRequestConditionProperty.LEASE_ID) | ||
&& requestConditions.getLeaseId() != null) { | ||
throw LOGGER.logExceptionAsError(new IllegalArgumentException("'leaseId' is not applicable to this API.")); | ||
invalidConditionsFound.add(BlobRequestConditionProperty.LEASE_ID.toString()); | ||
} | ||
if (invalidConditions.contains(BlobRequestConditionProperty.TAGS_CONDITIONS) | ||
&& requestConditions.getTagsConditions() != null) { | ||
throw LOGGER.logExceptionAsError(new IllegalArgumentException("'tagsConditions' is not applicable to " | ||
+ "this API.")); | ||
invalidConditionsFound.add(BlobRequestConditionProperty.TAGS_CONDITIONS.toString()); | ||
} | ||
if (invalidConditions.contains(BlobRequestConditionProperty.IF_MODIFIED_SINCE) | ||
&& requestConditions.getIfModifiedSince() != null) { | ||
throw LOGGER.logExceptionAsError(new IllegalArgumentException("'ifModifiedSince' is not applicable to " | ||
+ "this API.")); | ||
invalidConditionsFound.add(BlobRequestConditionProperty.IF_MODIFIED_SINCE.toString()); | ||
} | ||
if (invalidConditions.contains(BlobRequestConditionProperty.IF_UNMODIFIED_SINCE) | ||
&& requestConditions.getIfUnmodifiedSince() != null) { | ||
throw LOGGER.logExceptionAsError(new IllegalArgumentException("'ifUnmodifiedSince' is not applicable to " | ||
+ "this API.")); | ||
invalidConditionsFound.add(BlobRequestConditionProperty.IF_UNMODIFIED_SINCE.toString()); | ||
} | ||
if (invalidConditions.contains(BlobRequestConditionProperty.IF_MATCH) | ||
&& requestConditions.getIfMatch() != null) { | ||
throw LOGGER.logExceptionAsError(new IllegalArgumentException("'ifMatch' is not applicable to this API.")); | ||
invalidConditionsFound.add(BlobRequestConditionProperty.IF_MATCH.toString()); | ||
} | ||
if (invalidConditions.contains(BlobRequestConditionProperty.IF_NONE_MATCH) | ||
&& requestConditions.getIfNoneMatch() != null) { | ||
throw LOGGER.logExceptionAsError(new IllegalArgumentException("'ifNoneMatch' is not applicable to this " | ||
+ "API.")); | ||
invalidConditionsFound.add(BlobRequestConditionProperty.IF_NONE_MATCH.toString()); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How hot of a code path is this? Do we expect the general case for invalidConditions
to be empty or very full? We may be able to make this a little more readable and get some perf depending on the answer to those questions. Avoiding calling contains()
so often for a likely empty list is probably useful. IDK if this is more readable to you but it is to me. also we can flag missing enum cases as warnings if this expands later. (gihhub won't let me give a suggested edit here)
for (BlobRequestConditionProperty condition : invalidConditions) {
switch (condition) {
case LEASE_ID:
if (requestConditions.getLeaseId() != null) {
invalidConditionsFound.add(BlobRequestConditionProperty.LEASE_ID.toString());
}
break;
// other cases
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah that does look a lot better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we care about perf then bitflags could be an option.
if (invalidConditions.contains(BlobRequestConditionProperty.IF_MATCH) | ||
&& requestConditions.getIfMatch() != null) { | ||
throw LOGGER.logExceptionAsError(new IllegalArgumentException("'ifMatch' is not applicable to this API.")); | ||
List<String> invalidConditionsFound = new ArrayList<>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
most people will get it right, i.e. there won't be invalid conditions in API call. eventually they have to - otherwise API won't work.
Might be good to initialize this list in if
statements like we did in .net to avoid extra allocations.
No description provided.