-
Notifications
You must be signed in to change notification settings - Fork 2.2k
ServiceBus: SpotBugs P3 2 of 3 #3557
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
Changes from 3 commits
b0810e8
1d31051
e33c922
e6f203e
a12e7bc
130bbc2
57b450e
f9e3682
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,24 +3,22 @@ | |
|
|
||
| package com.microsoft.azure.servicebus.amqp; | ||
|
|
||
| import org.apache.qpid.proton.amqp.transport.*; | ||
|
|
||
| import org.apache.qpid.proton.amqp.transport.ErrorCondition; | ||
|
|
||
| /** | ||
| * All AmqpExceptions - which EventHub client handles internally. | ||
| */ | ||
| public class AmqpException extends Exception | ||
| { | ||
| public class AmqpException extends Exception { | ||
| private static final long serialVersionUID = -750417419234273714L; | ||
| private ErrorCondition errorCondition; | ||
| private transient ErrorCondition errorCondition; | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [SpotBugs-P3]
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the ErrorCondition already not serializable, Ignore it with using transient modifier to suppress the SpotBugs error |
||
|
|
||
| public AmqpException(ErrorCondition errorCondition) | ||
| { | ||
| public AmqpException(ErrorCondition errorCondition) { | ||
| super(errorCondition.getDescription()); | ||
| this.errorCondition = errorCondition; | ||
| } | ||
|
|
||
| public ErrorCondition getError() | ||
| { | ||
| public ErrorCondition getError() { | ||
| return this.errorCondition; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,25 +3,24 @@ | |
|
|
||
| package com.microsoft.azure.servicebus.primitives; | ||
|
|
||
| import java.io.Serializable; | ||
| import java.util.Locale; | ||
|
|
||
| abstract class ErrorContext | ||
| { | ||
| abstract class ErrorContext implements Serializable { | ||
|
|
||
| private static final long serialVersionUID = -6342329018037308640L; | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [SpotBugs] |
||
| private final String namespaceName; | ||
|
|
||
| ErrorContext(final String namespaceName) | ||
| { | ||
| ErrorContext(final String namespaceName) { | ||
| this.namespaceName = namespaceName; | ||
| } | ||
|
|
||
| protected String getNamespaceName() | ||
| { | ||
| protected String getNamespaceName() { | ||
| return this.namespaceName; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() | ||
| { | ||
| public String toString() { | ||
| return StringUtil.isNullOrEmpty(this.namespaceName) ? null : String.format(Locale.US, "NS: %s", this.namespaceName); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,186 +16,118 @@ | |
| import com.microsoft.azure.servicebus.amqp.AmqpErrorCode; | ||
| import com.microsoft.azure.servicebus.amqp.AmqpException; | ||
|
|
||
| public final class ExceptionUtil | ||
| { | ||
| static Exception toException(ErrorCondition errorCondition) | ||
| { | ||
| if (errorCondition == null) | ||
| { | ||
| public final class ExceptionUtil { | ||
| static Exception toException(ErrorCondition errorCondition) { | ||
| if (errorCondition == null) { | ||
| throw new IllegalArgumentException("'null' errorCondition cannot be translated to ServiceBusException"); | ||
| } | ||
| if (errorCondition.getCondition() == ClientConstants.TIMEOUT_ERROR) | ||
| { | ||
| if (errorCondition.getCondition() == ClientConstants.TIMEOUT_ERROR) { | ||
| return new TimeoutException(errorCondition.getDescription()); | ||
| } | ||
| else if (errorCondition.getCondition() == ClientConstants.SERVER_BUSY_ERROR) | ||
| { | ||
| } else if (errorCondition.getCondition() == ClientConstants.SERVER_BUSY_ERROR) { | ||
| return new ServerBusyException(errorCondition.getDescription()); | ||
| } | ||
| else if (errorCondition.getCondition() == AmqpErrorCode.NotFound) | ||
| { | ||
| } else if (errorCondition.getCondition() == AmqpErrorCode.NotFound) { | ||
| return new MessagingEntityNotFoundException(errorCondition.getDescription()); | ||
| } | ||
| else if (errorCondition.getCondition() == ClientConstants.ENTITY_DISABLED_ERROR) | ||
| { | ||
| } else if (errorCondition.getCondition() == ClientConstants.ENTITY_DISABLED_ERROR) { | ||
| return new MessagingEntityDisabledException(errorCondition.getDescription()); | ||
| } | ||
| else if (errorCondition.getCondition() == AmqpErrorCode.Stolen) | ||
| { | ||
| } else if (errorCondition.getCondition() == AmqpErrorCode.Stolen) { | ||
| return new ReceiverDisconnectedException(errorCondition.getDescription()); | ||
| } | ||
| else if (errorCondition.getCondition() == AmqpErrorCode.UnauthorizedAccess) | ||
| { | ||
| } else if (errorCondition.getCondition() == AmqpErrorCode.UnauthorizedAccess) { | ||
| return new AuthorizationFailedException(errorCondition.getDescription()); | ||
| } | ||
| else if (errorCondition.getCondition() == AmqpErrorCode.PayloadSizeExceeded) | ||
| { | ||
| } else if (errorCondition.getCondition() == AmqpErrorCode.PayloadSizeExceeded) { | ||
| return new PayloadSizeExceededException(errorCondition.getDescription()); | ||
| } | ||
| else if (errorCondition.getCondition() == AmqpErrorCode.InternalError) | ||
| { | ||
| } else if (errorCondition.getCondition() == AmqpErrorCode.InternalError) { | ||
| return new ServiceBusException(true, new AmqpException(errorCondition)); | ||
| } | ||
| else if (errorCondition.getCondition() == ClientConstants.ARGUMENT_ERROR) | ||
| { | ||
| } else if (errorCondition.getCondition() == ClientConstants.ARGUMENT_ERROR) { | ||
| return new ServiceBusException(false, errorCondition.getDescription(), new AmqpException(errorCondition)); | ||
| } | ||
| else if (errorCondition.getCondition() == ClientConstants.ARGUMENT_OUT_OF_RANGE_ERROR) | ||
| { | ||
| } else if (errorCondition.getCondition() == ClientConstants.ARGUMENT_OUT_OF_RANGE_ERROR) { | ||
| return new ServiceBusException(false, errorCondition.getDescription(), new AmqpException(errorCondition)); | ||
| } | ||
| else if (errorCondition.getCondition() == AmqpErrorCode.NotImplemented) | ||
| { | ||
| } else if (errorCondition.getCondition() == AmqpErrorCode.NotImplemented) { | ||
| return new UnsupportedOperationException(errorCondition.getDescription()); | ||
| } | ||
| else if (errorCondition.getCondition() == AmqpErrorCode.NotAllowed) | ||
| { | ||
| } else if (errorCondition.getCondition() == AmqpErrorCode.NotAllowed) { | ||
| return new UnsupportedOperationException(errorCondition.getDescription()); | ||
| } | ||
| else if (errorCondition.getCondition() == ClientConstants.PARTITION_NOT_OWNED_ERROR) | ||
| { | ||
| } else if (errorCondition.getCondition() == ClientConstants.PARTITION_NOT_OWNED_ERROR) { | ||
| return new ServiceBusException(false, errorCondition.getDescription()); | ||
| } | ||
| else if (errorCondition.getCondition() == ClientConstants.STORE_LOCK_LOST_ERROR) | ||
| { | ||
| } else if (errorCondition.getCondition() == ClientConstants.STORE_LOCK_LOST_ERROR) { | ||
| return new ServiceBusException(false, errorCondition.getDescription()); | ||
| } | ||
| else if (errorCondition.getCondition() == AmqpErrorCode.AmqpLinkDetachForced) | ||
| { | ||
| } else if (errorCondition.getCondition() == AmqpErrorCode.AmqpLinkDetachForced) { | ||
| return new ServiceBusException(true, new AmqpException(errorCondition)); | ||
| } | ||
| else if (errorCondition.getCondition() == AmqpErrorCode.ConnectionForced) | ||
| { | ||
| } else if (errorCondition.getCondition() == AmqpErrorCode.ConnectionForced) { | ||
| return new ServiceBusException(true, new AmqpException(errorCondition)); | ||
| } | ||
| else if (errorCondition.getCondition() == AmqpErrorCode.FramingError) | ||
| { | ||
| } else if (errorCondition.getCondition() == AmqpErrorCode.FramingError) { | ||
| return new ServiceBusException(true, new AmqpException(errorCondition)); | ||
| } | ||
| else if (errorCondition.getCondition() == AmqpErrorCode.ResourceLimitExceeded) | ||
| { | ||
| } else if (errorCondition.getCondition() == AmqpErrorCode.ResourceLimitExceeded) { | ||
| return new QuotaExceededException(errorCondition.getDescription()); | ||
| } | ||
| else if (errorCondition.getCondition() == ClientConstants.MESSAGE_LOCK_LOST_ERROR) | ||
| { | ||
| } else if (errorCondition.getCondition() == ClientConstants.MESSAGE_LOCK_LOST_ERROR) { | ||
| return new MessageLockLostException(errorCondition.getDescription()); | ||
| } | ||
| else if (errorCondition.getCondition() == ClientConstants.SESSION_LOCK_LOST_ERROR) | ||
| { | ||
| } else if (errorCondition.getCondition() == ClientConstants.SESSION_LOCK_LOST_ERROR) { | ||
| return new SessionLockLostException(errorCondition.getDescription()); | ||
| } | ||
| else if (errorCondition.getCondition() == ClientConstants.SESSIONS_CANNOT_BE_LOCKED_ERROR) | ||
| { | ||
| } else if (errorCondition.getCondition() == ClientConstants.SESSIONS_CANNOT_BE_LOCKED_ERROR) { | ||
| return new SessionCannotBeLockedException(errorCondition.getDescription()); | ||
| } | ||
| else if (errorCondition.getCondition() == ClientConstants.MESSAGE_NOT_FOUND_ERROR) | ||
| { | ||
| } else if (errorCondition.getCondition() == ClientConstants.MESSAGE_NOT_FOUND_ERROR) { | ||
| return new MessageNotFoundException(errorCondition.getDescription()); | ||
| } | ||
| else if (errorCondition.getCondition() == ClientConstants.ENTITY_ALREADY_EXISTS_ERROR) | ||
| { | ||
| } else if (errorCondition.getCondition() == ClientConstants.ENTITY_ALREADY_EXISTS_ERROR) { | ||
| return new MessagingEntityAlreadyExistsException(errorCondition.getDescription()); | ||
| } | ||
| else if (errorCondition.getCondition() == AmqpErrorCode.DecodeError) | ||
| { | ||
| } else if (errorCondition.getCondition() == AmqpErrorCode.DecodeError) { | ||
| return new ServiceBusException(false, new AmqpException(errorCondition)); | ||
| } | ||
|
|
||
| return new ServiceBusException(ClientConstants.DEFAULT_IS_TRANSIENT, errorCondition.toString()); | ||
| } | ||
|
|
||
| static <T> void completeExceptionally(CompletableFuture<T> future, Throwable exception, IErrorContextProvider contextProvider, boolean completeAsynchronously) | ||
| { | ||
| if (exception != null && exception instanceof ServiceBusException) | ||
| { | ||
| static <T> void completeExceptionally(CompletableFuture<T> future, Throwable exception, IErrorContextProvider contextProvider, boolean completeAsynchronously) { | ||
| if (exception != null && exception instanceof ServiceBusException) { | ||
| ErrorContext errorContext = contextProvider.getContext(); | ||
| ((ServiceBusException) exception).setContext(errorContext); | ||
| } | ||
|
|
||
| if(completeAsynchronously) | ||
| { | ||
| if(completeAsynchronously) { | ||
| AsyncUtil.completeFutureExceptionally(future, exception); | ||
| } | ||
| else | ||
| { | ||
| } else { | ||
| future.completeExceptionally(exception); | ||
| } | ||
| } | ||
|
|
||
| // not a specific message related error | ||
| static boolean isGeneralError(Symbol amqpError) | ||
| { | ||
| static boolean isGeneralError(Symbol amqpError) { | ||
| return (amqpError == ClientConstants.SERVER_BUSY_ERROR | ||
| || amqpError == ClientConstants.TIMEOUT_ERROR | ||
| || amqpError == AmqpErrorCode.ResourceLimitExceeded); | ||
| } | ||
|
|
||
| static String getTrackingIDAndTimeToLog() | ||
| { | ||
| static String getTrackingIDAndTimeToLog() { | ||
| return String.format(Locale.US, "TrackingId: %s, at: %s", UUID.randomUUID().toString(), ZonedDateTime.now()); | ||
| } | ||
|
|
||
| static String toStackTraceString(final Throwable exception, final String customErrorMessage) | ||
| { | ||
| static String toStackTraceString(final Throwable exception, final String customErrorMessage) { | ||
| final StringBuilder builder = new StringBuilder(); | ||
|
|
||
| if (!StringUtil.isNullOrEmpty(customErrorMessage)) | ||
| { | ||
| if (!StringUtil.isNullOrEmpty(customErrorMessage)) { | ||
| builder.append(customErrorMessage); | ||
| builder.append(System.lineSeparator()); | ||
| } | ||
|
|
||
| builder.append(exception.getMessage()); | ||
| if (exception.getStackTrace() != null) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [SpotBugs-P3] |
||
| for (StackTraceElement ste: exception.getStackTrace()) | ||
| { | ||
| builder.append(System.lineSeparator()); | ||
| builder.append(ste.toString()); | ||
| } | ||
| for (StackTraceElement ste : exception.getStackTrace()) { | ||
| builder.append(System.lineSeparator()); | ||
| builder.append(ste.toString()); | ||
| } | ||
|
|
||
| Throwable innerException = exception.getCause(); | ||
| if (innerException != null) | ||
| { | ||
| if (innerException != null) { | ||
| builder.append("Cause: " + innerException.getMessage()); | ||
| if (innerException.getStackTrace() != null) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [SpotBugs-P3] |
||
| for (StackTraceElement ste: innerException.getStackTrace()) | ||
| { | ||
| builder.append(System.lineSeparator()); | ||
| builder.append(ste.toString()); | ||
| } | ||
| for (StackTraceElement ste : innerException.getStackTrace()) { | ||
| builder.append(System.lineSeparator()); | ||
| builder.append(ste.toString()); | ||
| } | ||
| } | ||
|
|
||
| return builder.toString(); | ||
| } | ||
|
|
||
| public static Throwable extractAsyncCompletionCause(Throwable completionEx) | ||
| { | ||
| if(completionEx instanceof CompletionException || completionEx instanceof ExecutionException) | ||
| { | ||
| public static Throwable extractAsyncCompletionCause(Throwable completionEx) { | ||
| if(completionEx instanceof CompletionException || completionEx instanceof ExecutionException) { | ||
| return completionEx.getCause(); | ||
| } | ||
| else | ||
| { | ||
| } else { | ||
| return completionEx; | ||
| } | ||
| } | ||
|
|
||
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.
[SpotBugs-P3]
Sequence of calls to java.util.concurrent.ConcurrentHashMap may not be atomic in com.microsoft.azure.servicebus.MessageReceiver.lambda$renewMessageLockBatchAsync$20(UUID[], Collection)