-
Notifications
You must be signed in to change notification settings - Fork 2.2k
ServiceBus: SpotBugs P2 part 3 of 3 #3528
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 all commits
5f2d140
082b235
34d49a7
53bea12
7fefa13
c047f45
5753647
5f0e741
e58a4bc
c437495
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 |
|---|---|---|
|
|
@@ -52,20 +52,17 @@ private static SubscriptionRuntimeInfo parseFromEntry(String topicPath, Node xEn | |
| Node node = nList.item(i); | ||
| if (node.getNodeType() == Node.ELEMENT_NODE) { | ||
| Element element = (Element)node; | ||
| switch(element.getTagName()) | ||
| { | ||
| switch (element.getTagName()) { | ||
| case "title": | ||
| runtimeInfo = new SubscriptionRuntimeInfo(topicPath, element.getFirstChild().getNodeValue()); | ||
| break; | ||
| case "content": | ||
| NodeList qdNodes = element.getFirstChild().getChildNodes(); | ||
| for (int j = 0; j < qdNodes.getLength(); j++) | ||
| { | ||
| for (int j = 0; j < qdNodes.getLength(); j++) { | ||
| node = qdNodes.item(j); | ||
| if (node.getNodeType() == Node.ELEMENT_NODE) { | ||
| element = (Element) node; | ||
| switch (element.getTagName()) | ||
| { | ||
| switch (element.getTagName()) { | ||
| case "AccessedAt": | ||
| runtimeInfo.setAccessedAt(Instant.parse(element.getFirstChild().getNodeValue())); | ||
| break; | ||
|
|
@@ -102,6 +99,8 @@ private static SubscriptionRuntimeInfo parseFromEntry(String topicPath, Node xEn | |
| case "TransferDeadLetterMessageCount": | ||
| runtimeInfo.getMessageCountDetails().setTransferDeadLetterMessageCount(Long.parseLong(element.getFirstChild().getNodeValue())); | ||
| break; | ||
| default: | ||
|
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-P2]: Switch statement found in com.microsoft.azure.servicebus.management.SubscriptionRuntimeInfoSerializer.parseFromEntry(String, Node) where default case is missing |
||
| break; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,16 +31,14 @@ public class TopicDescription { | |
| * Max length is 260 chars. Cannot start or end with a slash. | ||
| * Cannot have restricted characters: '@','?','#','*' | ||
| */ | ||
| public TopicDescription(String path) | ||
| { | ||
| public TopicDescription(String path) { | ||
| this.setPath(path); | ||
| } | ||
|
|
||
| /** | ||
| * @return the path of the topic. | ||
| */ | ||
| public String getPath() | ||
| { | ||
| public String getPath() { | ||
| return this.path; | ||
| } | ||
|
|
||
|
|
@@ -49,8 +47,7 @@ public String getPath() | |
| * Max length is 260 chars. Cannot start or end with a slash. | ||
| * Cannot have restricted characters: '@','?','#','*' | ||
| */ | ||
| private void setPath(String path) | ||
| { | ||
| private void setPath(String path) { | ||
| EntityNameHelper.checkValidTopicName(path); | ||
| this.path = path; | ||
| } | ||
|
|
@@ -66,8 +63,7 @@ public long getMaxSizeInMB() { | |
| /** | ||
| * @param maxSize - Sets the maximum size of the topic in megabytes, which is the size of memory allocated for the topic. | ||
| */ | ||
| public void setMaxSizeInMB(long maxSize) | ||
| { | ||
| public void setMaxSizeInMB(long maxSize) { | ||
| this.maxSizeInMB = maxSize; | ||
| } | ||
|
|
||
|
|
@@ -106,10 +102,9 @@ public Duration getDefaultMessageTimeToLive() { | |
| * See {@link #getDefaultMessageTimeToLive()} | ||
| */ | ||
| public void setDefaultMessageTimeToLive(Duration defaultMessageTimeToLive) { | ||
| if (defaultMessageTimeToLive != null && | ||
| (defaultMessageTimeToLive.compareTo(ManagementClientConstants.MIN_ALLOWED_TTL) < 0 || | ||
| defaultMessageTimeToLive.compareTo(ManagementClientConstants.MAX_ALLOWED_TTL) > 0)) | ||
|
Member
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. Same null check as I suggested in my last comment. |
||
| { | ||
| if (defaultMessageTimeToLive == null | ||
| || (defaultMessageTimeToLive.compareTo(ManagementClientConstants.MIN_ALLOWED_TTL) < 0 | ||
| || defaultMessageTimeToLive.compareTo(ManagementClientConstants.MAX_ALLOWED_TTL) > 0)) { | ||
| throw new IllegalArgumentException( | ||
| String.format("The value must be between %s and %s.", | ||
| ManagementClientConstants.MAX_ALLOWED_TTL, | ||
|
|
@@ -132,9 +127,8 @@ public Duration getAutoDeleteOnIdle() { | |
| * The minimum duration is 5 minutes. | ||
| */ | ||
| public void setAutoDeleteOnIdle(Duration autoDeleteOnIdle) { | ||
| if (autoDeleteOnIdle != null && | ||
| autoDeleteOnIdle.compareTo(ManagementClientConstants.MIN_ALLOWED_AUTODELETE_DURATION) < 0) | ||
| { | ||
| if (autoDeleteOnIdle == null | ||
| || autoDeleteOnIdle.compareTo(ManagementClientConstants.MIN_ALLOWED_AUTODELETE_DURATION) < 0) { | ||
| throw new IllegalArgumentException( | ||
| String.format("The value must be greater than %s.", | ||
| ManagementClientConstants.MIN_ALLOWED_AUTODELETE_DURATION)); | ||
|
|
@@ -159,10 +153,9 @@ public Duration getDuplicationDetectionHistoryTimeWindow() { | |
| * Max value is 1 day and minimum is 20 seconds. | ||
| */ | ||
| public void setDuplicationDetectionHistoryTimeWindow(Duration duplicationDetectionHistoryTimeWindow) { | ||
| if (duplicationDetectionHistoryTimeWindow != null && | ||
| (duplicationDetectionHistoryTimeWindow.compareTo(ManagementClientConstants.MIN_DUPLICATE_HISTORY_DURATION) < 0 || | ||
| duplicationDetectionHistoryTimeWindow.compareTo(ManagementClientConstants.MAX_DUPLICATE_HISTORY_DURATION) > 0)) | ||
| { | ||
| if (duplicationDetectionHistoryTimeWindow == null | ||
| || (duplicationDetectionHistoryTimeWindow.compareTo(ManagementClientConstants.MIN_DUPLICATE_HISTORY_DURATION) < 0 | ||
| || duplicationDetectionHistoryTimeWindow.compareTo(ManagementClientConstants.MAX_DUPLICATE_HISTORY_DURATION) > 0)) { | ||
| throw new IllegalArgumentException( | ||
| String.format("The value must be between %s and %s.", | ||
| ManagementClientConstants.MIN_DUPLICATE_HISTORY_DURATION, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -176,20 +176,17 @@ private static TopicDescription parseFromEntry(Node xEntry) { | |
| Node node = nList.item(i); | ||
| if (node.getNodeType() == Node.ELEMENT_NODE) { | ||
| Element element = (Element)node; | ||
| switch(element.getTagName()) | ||
| { | ||
| switch (element.getTagName()) { | ||
| case "title": | ||
| td = new TopicDescription(element.getFirstChild().getNodeValue()); | ||
| break; | ||
| case "content": | ||
| NodeList qdNodes = element.getFirstChild().getChildNodes(); | ||
| for (int j = 0; j < qdNodes.getLength(); j++) | ||
| { | ||
| for (int j = 0; j < qdNodes.getLength(); j++) { | ||
| node = qdNodes.item(j); | ||
| if (node.getNodeType() == Node.ELEMENT_NODE) { | ||
| element = (Element) node; | ||
| switch (element.getTagName()) | ||
| { | ||
| switch (element.getTagName()) { | ||
| case "MaxSizeInMegabytes": | ||
| td.maxSizeInMB = Long.parseLong(element.getFirstChild().getNodeValue()); | ||
| break; | ||
|
|
@@ -223,6 +220,8 @@ private static TopicDescription parseFromEntry(Node xEntry) { | |
| case "SupportOrdering": | ||
| td.supportOrdering = Boolean.parseBoolean(element.getFirstChild().getNodeValue()); | ||
| break; | ||
| default: | ||
|
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-P2] Switch statement found in com.microsoft.azure.servicebus.management.TopicDescriptionSerializer.parseFromEntry(Node) where default case is missing |
||
| break; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -52,20 +52,17 @@ private static TopicRuntimeInfo parseFromEntry(Node xEntry) { | |
| Node node = nList.item(i); | ||
| if (node.getNodeType() == Node.ELEMENT_NODE) { | ||
| Element element = (Element)node; | ||
| switch(element.getTagName()) | ||
| { | ||
| switch (element.getTagName()) { | ||
| case "title": | ||
| topicRuntimeInfo = new TopicRuntimeInfo(element.getFirstChild().getNodeValue()); | ||
| break; | ||
| case "content": | ||
| NodeList qdNodes = element.getFirstChild().getChildNodes(); | ||
| for (int j = 0; j < qdNodes.getLength(); j++) | ||
| { | ||
| for (int j = 0; j < qdNodes.getLength(); j++) { | ||
| node = qdNodes.item(j); | ||
| if (node.getNodeType() == Node.ELEMENT_NODE) { | ||
| element = (Element) node; | ||
| switch (element.getTagName()) | ||
| { | ||
| switch (element.getTagName()) { | ||
| case "AccessedAt": | ||
| topicRuntimeInfo.setAccessedAt(Instant.parse(element.getFirstChild().getNodeValue())); | ||
| break; | ||
|
|
@@ -105,6 +102,8 @@ private static TopicRuntimeInfo parseFromEntry(Node xEntry) { | |
| case "TransferDeadLetterMessageCount": | ||
| topicRuntimeInfo.getMessageCountDetails().setTransferDeadLetterMessageCount(Long.parseLong(element.getFirstChild().getNodeValue())); | ||
| break; | ||
| default: | ||
|
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-P2]: Switch statement found in com.microsoft.azure.servicebus.management.TopicRuntimeInfoSerializer.parseFromEntry(Node) where default case is missing |
||
| break; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,10 @@ | |
|
|
||
| package com.microsoft.azure.servicebus.primitives; | ||
|
|
||
| import java.io.File; | ||
| import java.io.FileInputStream; | ||
| import java.io.IOException; | ||
| import java.io.InputStream; | ||
| import java.time.Duration; | ||
| import java.util.Properties; | ||
| import java.util.UUID; | ||
|
|
@@ -190,12 +194,22 @@ private ClientConstants() { } | |
| private static String getClientVersion() { | ||
| String clientVersion; | ||
| final Properties properties = new Properties(); | ||
| InputStream clientPropInputStream = null; | ||
| try { | ||
| properties.load(ClientConstants.class.getResourceAsStream("/client.properties")); | ||
|
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-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. |
||
| clientPropInputStream = ClientConstants.class.getResourceAsStream("/client.properties"); | ||
| properties.load(clientPropInputStream); | ||
| clientVersion = properties.getProperty("client.version"); | ||
| } catch (Exception e) { | ||
| clientVersion = "NOTFOUND"; | ||
| TRACE_LOGGER.error("Exception while retrieving client version. Exception: ", e.toString()); | ||
| } finally { | ||
| if (clientPropInputStream != null) { | ||
| try { | ||
| clientPropInputStream.close(); | ||
|
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. close the clientPropInputStream |
||
| } catch (IOException e) { | ||
| TRACE_LOGGER.error("Client Properties InputStream doesn't close properly. Exception: ", e.toString()); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return clientVersion; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,12 +25,13 @@ | |
| import java.util.HashMap; | ||
| import java.util.Map; | ||
| import java.util.concurrent.CompletableFuture; | ||
| import java.util.concurrent.atomic.AtomicBoolean; | ||
|
|
||
| class Controller { | ||
| private static final Logger TRACE_LOGGER = LoggerFactory.getLogger(Controller.class); | ||
| private MessagingFactory messagingFactory; | ||
| private CoreMessageSender internalSender; | ||
| private boolean isInitialized = false; | ||
| private AtomicBoolean isInitialized = new AtomicBoolean(false); | ||
| private URI namespaceEndpointURI; | ||
| private ClientSettings clientSettings; | ||
|
|
||
|
|
@@ -41,7 +42,7 @@ class Controller { | |
| } | ||
|
|
||
| synchronized CompletableFuture<Void> initializeAsync() { | ||
| if (this.isInitialized) { | ||
|
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-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 |
||
| if (this.isInitialized.get()) { | ||
| return CompletableFuture.completedFuture(null); | ||
| } else { | ||
| TRACE_LOGGER.info("Creating MessageSender to coordinator"); | ||
|
|
@@ -54,7 +55,7 @@ synchronized CompletableFuture<Void> initializeAsync() { | |
| senderFuture.handleAsync((s, coreSenderCreationEx) -> { | ||
| if (coreSenderCreationEx == null) { | ||
| this.internalSender = s; | ||
| this.isInitialized = true; | ||
| this.isInitialized.set(true); | ||
| TRACE_LOGGER.info("Created MessageSender to coordinator"); | ||
| postSenderCreationFuture.complete(null); | ||
| } else { | ||
|
|
@@ -72,7 +73,7 @@ synchronized CompletableFuture<Void> initializeAsync() { | |
| public CompletableFuture<Binary> declareAsync() { | ||
| Message message = Message.Factory.create(); | ||
| Declare declare = new Declare(); | ||
| message.setBody(new AmqpValue(declare)); | ||
| message.setBody(new AmqpValue(declare)); | ||
|
|
||
| return this.internalSender.sendAndReturnDeliveryStateAsync( | ||
| message, | ||
|
|
||
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-P2]: Switch statement found in com.microsoft.azure.servicebus.management.SubscriptionDescriptionSerializer.parseFromEntry(String, Node) where default case is missing