Skip to content

ServiceBus: SpotBugs P2 part 3 of 3#3528

Merged
mssfang merged 10 commits intoAzure:masterfrom
mssfang:ServiceBus-P2-Part3
May 17, 2019
Merged

ServiceBus: SpotBugs P2 part 3 of 3#3528
mssfang merged 10 commits intoAzure:masterfrom
mssfang:ServiceBus-P2-Part3

Conversation

@mssfang
Copy link
Contributor

@mssfang mssfang commented May 6, 2019

This PR contains:

(1) P2 SpotBugs: search [SpotBugs-P2] for detail explanation
(2) CheckStyles errors to these changed files

@mssfang mssfang added Service Bus Client This issue points to a problem in the data-plane of the library. labels May 6, 2019
@mssfang mssfang self-assigned this May 6, 2019
sd.forwardDeadLetteredMessagesTo = fwdDlq.getNodeValue();
}
break;
default:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

[SpotBugs-P2]: Switch statement found in com.microsoft.azure.servicebus.management.SubscriptionDescriptionSerializer.parseFromEntry(String, Node) where default case is missing

case "TransferDeadLetterMessageCount":
runtimeInfo.getMessageCountDetails().setTransferDeadLetterMessageCount(Long.parseLong(element.getFirstChild().getNodeValue()));
break;
default:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

[SpotBugs-P2]: Switch statement found in com.microsoft.azure.servicebus.management.SubscriptionRuntimeInfoSerializer.parseFromEntry(String, Node) where default case is missing

case "SupportOrdering":
td.supportOrdering = Boolean.parseBoolean(element.getFirstChild().getNodeValue());
break;
default:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

[SpotBugs-P2] Switch statement found in com.microsoft.azure.servicebus.management.TopicDescriptionSerializer.parseFromEntry(Node) where default case is missing

case "TransferDeadLetterMessageCount":
topicRuntimeInfo.getMessageCountDetails().setTransferDeadLetterMessageCount(Long.parseLong(element.getFirstChild().getNodeValue()));
break;
default:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

[SpotBugs-P2]: Switch statement found in com.microsoft.azure.servicebus.management.TopicRuntimeInfoSerializer.parseFromEntry(Node) where default case is missing

final Properties properties = new Properties();
InputStream clientPropInputStream = null;
try {
properties.load(ClientConstants.class.getResourceAsStream("/client.properties"));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

[SpotBugs-P2]: com.microsoft.azure.servicebus.primitives.ClientConstants.getClientVersion() may fail to clean up java.io.InputStream

This method may fail to clean up (close, dispose of) a stream, database object, or other resource requiring an explicit cleanup operation.
In general, if a method opens a stream or other resource, the method should use a try/finally block to ensure that the stream or resource is cleaned up before the method returns.
This bug pattern is essentially the same as the OS_OPEN_STREAM and ODR_OPEN_DATABASE_RESOURCE bug patterns, but is based on a different (and hopefully better) static analysis technique. We are interested is getting feedback about the usefulness of this bug pattern. For sending feedback, check:
contributing guideline
malinglist
In particular, the false-positive suppression heuristics for this bug pattern have not been extensively tuned, so reports about false positives are helpful to us.
See Weimer and Necula, Finding and Preventing Run-Time Error Handling Mistakes, for a description of the analysis technique.

}

synchronized CompletableFuture<Void> initializeAsync() {
if (this.isInitialized) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

[SpotBugs-P2]: Inconsistent synchronization of com.microsoft.azure.servicebus.primitives.Controller.isInitialized; locked 50% of time

The fields of this class appear to be accessed inconsistently with respect to synchronization. This bug report indicates that the bug pattern detector judged that
The class contains a mix of locked and unlocked accesses,
The class is not annotated as javax.annotation.concurrent.NotThreadSafe,
At least one locked access was performed by one of the class's own methods, and
The number of unsynchronized field accesses (reads and writes) was no more than one third of all accesses, with writes being weighed twice as high as reads
A typical bug matching this bug pattern is forgetting to synchronize one of the methods in a class that is intended to be thread-safe.
You can select the nodes labeled "Unsynchronized access" to show the code locations where the detector believed that a field was accessed without synchronization.
Note that there are various sources of inaccuracy in this detector; for example, the detector cannot statically detect all situations in which a lock is held. Also, even when the detector is accurate in distinguishing locked vs. unlocked accesses, the code in question may still be correct.

@azuresdkci
Copy link
Contributor

Can one of the admins verify this patch?

@mssfang mssfang requested review from conniey and yvgopal May 6, 2019 01:05
@mssfang mssfang changed the title ServiceBugs: SpotBugs P2 part 3 of 3 ServiceBus: SpotBugs P2 part 3 of 3 May 7, 2019
Copy link
Member

@conniey conniey left a comment

Choose a reason for hiding this comment

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

Some changes with those null pointer fixes.

(defaultMessageTimeToLive.compareTo(ManagementClientConstants.MIN_ALLOWED_TTL) < 0 ||
defaultMessageTimeToLive.compareTo(ManagementClientConstants.MAX_ALLOWED_TTL) > 0))
{
if (defaultMessageTimeToLive != null
Copy link
Member

Choose a reason for hiding this comment

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

f (defaultMessageTimeToLive != null [](start = 9, length = 35)

May be you can change it to defaultMessageTimeToLive == null. That way it will throw a validation exception for the null case too. Can you do for every Description class where this null check is not done?

Copy link
Contributor Author

@mssfang mssfang May 16, 2019

Choose a reason for hiding this comment

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

Do you want to have all null checking for all setter methods that pass Object as parameters in the Description class if they don't handle NPE? Such as
public void setAuthorizationRules(List authorizationRules) {
this.authorizationRules = authorizationRules;
}

public void setDefaultMessageTimeToLive(Duration defaultMessageTimeToLive) {
if (defaultMessageTimeToLive != null &&
(defaultMessageTimeToLive.compareTo(ManagementClientConstants.MIN_ALLOWED_TTL) < 0 ||
defaultMessageTimeToLive.compareTo(ManagementClientConstants.MAX_ALLOWED_TTL) > 0))
Copy link
Member

Choose a reason for hiding this comment

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

Same null check as I suggested in my last comment.

public static <T> void completeFuture(CompletableFuture<T> future, T result)
{
public static <T> void completeFuture(CompletableFuture<T> future, T result) {
MessagingFactory.INTERNAL_THREAD_POOL.submit(new CompleteCallable<T>(future, result));
Copy link
Member

Choose a reason for hiding this comment

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

[](start = 73, length = 3)

Some places you removed the template type variable. Some places you didn't.

{
this.timedOutUpdateStateRequestsDaemon = () -> {
try {
if (TRACE_LOGGER.isTraceEnabled()) {
Copy link
Member

Choose a reason for hiding this comment

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

if (TRACE_LOGGER.isTraceEnabled()) { [](start = 16, length = 36)

Why are you checking isTraceEnabled()? With SLF4J, you don't have to do this as long as you are using string formatting properly. Remove these isLevelEnabled calls.

Copy link
Member

@yvgopal yvgopal left a comment

Choose a reason for hiding this comment

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

🕐

@mssfang mssfang requested review from conniey and yvgopal May 16, 2019 18:36
} finally {
if (clientPropInputStream != null) {
try {
clientPropInputStream.close();
Copy link
Contributor Author

@mssfang mssfang May 16, 2019

Choose a reason for hiding this comment

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

close the clientPropInputStream

@mssfang
Copy link
Contributor Author

mssfang commented May 17, 2019

@yvgopal There has no more spotbugs :). Can you review the changes? Thank you

Copy link
Member

@yvgopal yvgopal left a comment

Choose a reason for hiding this comment

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

:shipit:

@mssfang mssfang merged commit 435a7b0 into Azure:master May 17, 2019
@mssfang mssfang deleted the ServiceBus-P2-Part3 branch May 17, 2019 20:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Client This issue points to a problem in the data-plane of the library. Service Bus

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

Comments