Skip to content

Commit 36d12f8

Browse files
committed
Fix some Sonar warnings
1 parent c176ff9 commit 36d12f8

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
@@ -1099,7 +1099,9 @@ public Connection newConnection(ExecutorService executor, AddressResolver addres
10991099

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

11041106
conn.init();
11051107
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
@@ -30,13 +30,13 @@ public abstract class SslEngineConfigurators {
3030
/**
3131
* Default {@link SslEngineConfigurator}, does nothing.
3232
*/
33-
public static SslEngineConfigurator DEFAULT = sslEngine -> {
33+
public static final SslEngineConfigurator DEFAULT = sslEngine -> {
3434
};
3535

3636
/**
3737
* {@link SslEngineConfigurator} that enables server hostname verification.
3838
*/
39-
public static SslEngineConfigurator ENABLE_HOSTNAME_VERIFICATION = sslEngine -> {
39+
public static final SslEngineConfigurator ENABLE_HOSTNAME_VERIFICATION = sslEngine -> {
4040
SSLParameters sslParameters = SocketConfigurators.enableHostnameVerification(sslEngine.getSSLParameters());
4141
sslEngine.setSSLParameters(sslParameters);
4242
};

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public abstract class AMQChannel extends ShutdownNotifierComponent {
6868
private RpcWrapper _activeRpc = null;
6969

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

7373
/** Timeout for RPC calls */
7474
protected final int _rpcTimeout;
@@ -218,8 +218,9 @@ private void doEnqueueRpc(Supplier<RpcWrapper> rpcWrapperSupplier) {
218218
while (_activeRpc != null) {
219219
try {
220220
_channelMutex.wait();
221-
} catch (InterruptedException e) {
221+
} catch (InterruptedException e) { //NOSONAR
222222
waitClearedInterruptStatus = true;
223+
// No Sonar: we re-interrupt the thread later
223224
}
224225
}
225226
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
@@ -78,7 +78,10 @@ public FrameHandler create(Address addr, String connectionName) throws IOExcepti
7878
}
7979

8080
SocketAddress address = new InetSocketAddress(addr.getHost(), portNumber);
81-
channel = SocketChannel.open();
81+
// No Sonar: the channel is closed in case of error and it cannot
82+
// be closed here because it's part of the state of the connection
83+
// to be returned.
84+
channel = SocketChannel.open(); //NOSONAR
8285
channel.configureBlocking(true);
8386
if(nioParams.getSocketChannelConfigurator() != null) {
8487
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
@@ -761,7 +761,8 @@ public void automaticallyRecover(AutorecoveringConnection connection, Connection
761761
this.connection = connection;
762762

763763
final RecoveryAwareChannelN newChannel = (RecoveryAwareChannelN) connDelegate.createChannel(this.getChannelNumber());
764-
if (newChannel == null)
764+
// No Sonar: the channel could be null
765+
if (newChannel == null) //NOSONAR
765766
throw new IOException("Failed to create new channel for channel number=" + this.getChannelNumber() + " during recovery");
766767
newChannel.inheritOffsetFrom(defunctChannel);
767768
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
@@ -163,7 +163,8 @@ public void init() throws IOException, TimeoutException {
163163
@Override
164164
public Channel createChannel() throws IOException {
165165
RecoveryAwareChannelN ch = (RecoveryAwareChannelN) delegate.createChannel();
166-
if (ch == null) {
166+
// No Sonar: the channel could be null
167+
if (ch == null) { //NOSONAR
167168
return null;
168169
} else {
169170
return this.wrapChannel(ch);
@@ -599,7 +600,9 @@ private RecoveryAwareAMQConnection recoverConnection() throws InterruptedExcepti
599600
while (!manuallyClosed) {
600601
try {
601602
attempts++;
602-
RecoveryAwareAMQConnection newConn = this.cf.newConnection();
603+
// No Sonar: no need to close this resource because we're the one that creates it
604+
// and hands it over to the user
605+
RecoveryAwareAMQConnection newConn = this.cf.newConnection(); //NOSONAR
603606
synchronized(recoveryLock) {
604607
if (!manuallyClosed) {
605608
// This is the standard case.

src/main/java/com/rabbitmq/utility/Utility.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ public static <T extends Throwable & SensibleClone<T>> T fixStackTrace(T throwab
8282
* @return ArrayList copy of the list
8383
*/
8484
public static <E> List<E> copy(final List<E> list) {
85-
synchronized (list) {
85+
// No Sonar: this very list instance can be synchronized in other places of its owning class
86+
synchronized (list) { //NOSONAR
8687
return new ArrayList<E>(list);
8788
}
8889
}
@@ -96,7 +97,8 @@ public static <E> List<E> copy(final List<E> list) {
9697
* @return LinkedHashMap copy of the map
9798
*/
9899
public static <K, V> Map<K, V> copy(final Map<K, V> map) {
99-
synchronized (map) {
100+
// No Sonar: this very map instance can be synchronized in other places of its owning class
101+
synchronized (map) { //NOSONAR
100102
return new LinkedHashMap<K, V>(map);
101103
}
102104
}

0 commit comments

Comments
 (0)