Skip to content

Commit f0c08fc

Browse files
committed
Fix some Sonar warnings
(cherry picked from commit 36d12f8) Conflicts: src/main/java/com/rabbitmq/client/SslEngineConfigurators.java
1 parent c5923a6 commit f0c08fc

11 files changed

+36
-18
lines changed

src/main/java/com/rabbitmq/client/ConnectionFactory.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1154,7 +1154,9 @@ public Connection newConnection(ExecutorService executor, AddressResolver addres
11541154

11551155
if (isAutomaticRecoveryEnabled()) {
11561156
// see com.rabbitmq.client.impl.recovery.RecoveryAwareAMQConnectionFactory#newConnection
1157-
AutorecoveringConnection conn = new AutorecoveringConnection(params, fhFactory, addressResolver, metricsCollector);
1157+
// No Sonar: no need to close this resource because we're the one that creates it
1158+
// and hands it over to the user
1159+
AutorecoveringConnection conn = new AutorecoveringConnection(params, fhFactory, addressResolver, metricsCollector); //NOSONAR
11581160

11591161
conn.init();
11601162
return conn;

src/main/java/com/rabbitmq/client/ConnectionFactoryConfigurator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public class ConnectionFactoryConfigurator {
5454
public static final String DEFAULT_PREFIX = "rabbitmq.";
5555

5656
public static final String USERNAME = "username";
57-
public static final String PASSWORD = "password";
57+
public static final String PASSWORD = "password"; //NOSONAR
5858
public static final String VIRTUAL_HOST = "virtual.host";
5959
public static final String HOST = "host";
6060
public static final String PORT = "port";

src/main/java/com/rabbitmq/client/SslEngineConfigurators.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public abstract class SslEngineConfigurators {
3232
/**
3333
* Default {@link SslEngineConfigurator}, does nothing.
3434
*/
35-
public static AbstractSslEngineConfigurator DEFAULT = new AbstractSslEngineConfigurator() {
35+
public static final AbstractSslEngineConfigurator DEFAULT = new AbstractSslEngineConfigurator() {
3636

3737
@Override
3838
public void configure(SSLEngine sslEngine) {
@@ -46,7 +46,7 @@ public void configure(SSLEngine sslEngine) {
4646
* Requires Java 7 or more.
4747
*
4848
*/
49-
public static AbstractSslEngineConfigurator ENABLE_HOSTNAME_VERIFICATION = new AbstractSslEngineConfigurator() {
49+
public static final AbstractSslEngineConfigurator ENABLE_HOSTNAME_VERIFICATION = new AbstractSslEngineConfigurator() {
5050

5151
@Override
5252
public void configure(SSLEngine sslEngine) throws IOException {

src/main/java/com/rabbitmq/client/impl/AMQChannel.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public abstract class AMQChannel extends ShutdownNotifierComponent {
6666
private RpcContinuation _activeRpc = null;
6767

6868
/** Whether transmission of content-bearing methods should be blocked */
69-
public volatile boolean _blockContent = false;
69+
protected volatile boolean _blockContent = false;
7070

7171
/** Timeout for RPC calls */
7272
protected final int _rpcTimeout;
@@ -193,8 +193,9 @@ public void enqueueRpc(RpcContinuation k)
193193
while (_activeRpc != null) {
194194
try {
195195
_channelMutex.wait();
196-
} catch (InterruptedException e) {
196+
} catch (InterruptedException e) { //NOSONAR
197197
waitClearedInterruptStatus = true;
198+
// No Sonar: we re-interrupt the thread later
198199
}
199200
}
200201
if (waitClearedInterruptStatus) {

src/main/java/com/rabbitmq/client/impl/ChannelManager.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,14 @@ public void run() {
143143
for (CountDownLatch latch : sdSet) {
144144
try {
145145
int shutdownTimeout = ssWorkService.getShutdownTimeout();
146-
if (shutdownTimeout == 0) latch.await();
147-
else latch.await(shutdownTimeout, TimeUnit.MILLISECONDS);
146+
if (shutdownTimeout == 0) {
147+
latch.await();
148+
} else {
149+
boolean completed = latch.await(shutdownTimeout, TimeUnit.MILLISECONDS);
150+
if (!completed) {
151+
LOGGER.warn("Consumer dispatcher for channel didn't shutdown after waiting for {} ms", shutdownTimeout);
152+
}
153+
}
148154
} catch (Throwable e) {
149155
/*ignored*/
150156
}

src/main/java/com/rabbitmq/client/impl/ContentHeaderPropertyReader.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ public class ContentHeaderPropertyReader {
3434
private final ValueReader in;
3535

3636
/** Current field flag word */
37-
public int flagWord;
37+
private int flagWord;
3838

3939
/** Current flag position counter */
40-
public int bitCount;
40+
private int bitCount;
4141

4242
/**
4343
* Protected API - Constructs a reader from the given input stream

src/main/java/com/rabbitmq/client/impl/ContentHeaderPropertyWriter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ public class ContentHeaderPropertyWriter {
3333
private final ValueWriter out;
3434

3535
/** Current flags word being accumulated */
36-
public int flagWord;
36+
private int flagWord;
3737

3838
/** Position within current flags word */
39-
public int bitCount;
39+
private int bitCount;
4040

4141
/**
4242
* Constructs a fresh ContentHeaderPropertyWriter.

src/main/java/com/rabbitmq/client/impl/nio/SocketChannelFrameHandlerFactory.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,10 @@ public FrameHandler create(Address addr) throws IOException {
8282
}
8383

8484
SocketAddress address = new InetSocketAddress(addr.getHost(), portNumber);
85-
channel = SocketChannel.open();
85+
// No Sonar: the channel is closed in case of error and it cannot
86+
// be closed here because it's part of the state of the connection
87+
// to be returned.
88+
channel = SocketChannel.open(); //NOSONAR
8689
channel.configureBlocking(true);
8790
if(nioParams.getSocketChannelConfigurator() != null) {
8891
nioParams.getSocketChannelConfigurator().configure(channel);

src/main/java/com/rabbitmq/client/impl/recovery/AutorecoveringChannel.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,8 @@ public void automaticallyRecover(AutorecoveringConnection connection, Connection
592592
this.connection = connection;
593593

594594
final RecoveryAwareChannelN newChannel = (RecoveryAwareChannelN) connDelegate.createChannel(this.getChannelNumber());
595-
if (newChannel == null)
595+
// No Sonar: the channel could be null
596+
if (newChannel == null) //NOSONAR
596597
throw new IOException("Failed to create new channel for channel number=" + this.getChannelNumber() + " during recovery");
597598
newChannel.inheritOffsetFrom(defunctChannel);
598599
this.delegate = newChannel;

src/main/java/com/rabbitmq/client/impl/recovery/AutorecoveringConnection.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,8 @@ public void init() throws IOException, TimeoutException {
184184
@Override
185185
public Channel createChannel() throws IOException {
186186
RecoveryAwareChannelN ch = (RecoveryAwareChannelN) delegate.createChannel();
187-
if (ch == null) {
187+
// No Sonar: the channel could be null
188+
if (ch == null) { //NOSONAR
188189
return null;
189190
} else {
190191
return this.wrapChannel(ch);
@@ -605,7 +606,9 @@ private RecoveryAwareAMQConnection recoverConnection() throws InterruptedExcepti
605606
while (!manuallyClosed) {
606607
try {
607608
attempts++;
608-
RecoveryAwareAMQConnection newConn = this.cf.newConnection();
609+
// No Sonar: no need to close this resource because we're the one that creates it
610+
// and hands it over to the user
611+
RecoveryAwareAMQConnection newConn = this.cf.newConnection(); //NOSONAR
609612
synchronized(recoveryLock) {
610613
if (!manuallyClosed) {
611614
// This is the standard case.

0 commit comments

Comments
 (0)