Skip to content

Commit 3848ba6

Browse files
committed
Cleanup and fixes based on FindBugs analysis
1 parent 515cd32 commit 3848ba6

File tree

36 files changed

+498
-698
lines changed

36 files changed

+498
-698
lines changed

errai-bus-websocket/errai-bus-jboss7-websocket/src/main/java/org/jboss/websockets/oio/internal/util/Hash.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,14 @@ private Hash() {
4242
hashCounter = random.nextInt();
4343
random.nextBytes(seed = new byte[512]);
4444
}
45-
catch (NoSuchAlgorithmException e) {
45+
catch (final NoSuchAlgorithmException e) {
4646
throw new RuntimeException("runtime does not support secure random algorithm: " + secureRandomAlgorithm);
4747
}
4848
}
4949

5050
public static byte[] getRandomBytes(final byte[] bytes) {
5151
if (hashCounter < 0) {
52-
hashCounter -= hashCounter;
52+
hashCounter = 0;
5353
}
5454
for (int i = 0; i < bytes.length; i++) {
5555
hashCounter++;
@@ -82,7 +82,7 @@ private static String nextSecureHash(final String algorithm, final byte[] additi
8282
md.update(additionalSeed);
8383
}
8484

85-
byte[] randBytes = new byte[32];
85+
final byte[] randBytes = new byte[32];
8686
getRandomBytes(randBytes);
8787

8888
// 1,000 rounds.
@@ -92,14 +92,14 @@ private static String nextSecureHash(final String algorithm, final byte[] additi
9292

9393
return hashToHexString(md.digest());
9494
}
95-
catch (Exception e) {
95+
catch (final Exception e) {
9696
throw new RuntimeException("failed to generate session id hash", e);
9797
}
9898
}
9999

100100
public static String hashToHexString(byte[] hash) {
101101
final StringBuilder hexString = new StringBuilder(hash.length);
102-
for (byte mdbyte : hash) {
102+
for (final byte mdbyte : hash) {
103103
hexString.append(Integer.toHexString(0xFF & mdbyte));
104104
}
105105
return hexString.toString();

errai-bus/src/main/java/org/jboss/errai/bus/client/framework/AbstractRpcProxy.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,7 @@ public boolean error(Object message, Throwable throwable) {
5454

5555
@Override
5656
public void setErrorCallback(ErrorCallback errorCallback) {
57-
if (errorCallback == null) {
58-
errorCallback = defaultErrorCallback;
59-
}
60-
else {
57+
if (errorCallback != null) {
6158
this.errorCallback = errorCallback;
6259
}
6360
}

errai-bus/src/main/java/org/jboss/errai/bus/server/io/AbstractRPCMethodCallback.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,10 @@ protected AbstractRPCMethodCallback(final ServiceInstanceProvider genericSvc,
5050
}
5151

5252
public Object invokeMethodFromMessage(Message message) {
53+
@SuppressWarnings("unchecked")
5354
final List<Object> parms = message.get(List.class, "MethodParms");
5455

55-
if ((parms == null && targetTypes.length != 0) || (parms.size() != targetTypes.length)) {
56+
if ((parms == null && targetTypes.length != 0) || (parms != null && parms.size() != targetTypes.length)) {
5657
throw new MessageDeliveryFailure(
5758
"wrong number of arguments sent to endpoint. (received: "
5859
+ (parms == null ? 0 : parms.size())
@@ -61,19 +62,19 @@ public Object invokeMethodFromMessage(Message message) {
6162

6263
try {
6364
RpcContext.set(message);
64-
return method.invoke(serviceProvider.get(message), parms.toArray(new Object[parms.size()]));
65+
return method.invoke(serviceProvider.get(message), (parms != null) ? parms.toArray(new Object[parms.size()]) : new Object[0]);
6566
}
66-
catch (QueueUnavailableException e) {
67+
catch (final QueueUnavailableException e) {
6768
throw e;
6869
}
69-
catch (MessageDeliveryFailure e) {
70+
catch (final MessageDeliveryFailure e) {
7071
throw e;
7172
}
72-
catch (InvocationTargetException e) {
73+
catch (final InvocationTargetException e) {
7374
log.debug("RPC endpoint threw exception:", e.getCause());
7475
throw new MessageDeliveryFailure("error invoking RPC endpoint " + method, e.getCause(), true);
7576
}
76-
catch (Exception e) {
77+
catch (final Exception e) {
7778
throw new MessageDeliveryFailure("error invoking endpoint", e);
7879
}
7980
finally {

errai-bus/src/main/java/org/jboss/errai/bus/server/io/EndpointCallback.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@
1616

1717
package org.jboss.errai.bus.server.io;
1818

19+
import java.lang.reflect.Method;
20+
import java.util.List;
21+
22+
import org.jboss.errai.bus.client.api.base.MessageDeliveryFailure;
1923
import org.jboss.errai.bus.client.api.messaging.Message;
2024
import org.jboss.errai.bus.client.api.messaging.MessageCallback;
21-
import org.jboss.errai.bus.client.api.base.MessageDeliveryFailure;
2225
import org.mvel2.DataConversion;
2326

24-
import java.lang.reflect.Method;
25-
import java.util.List;
26-
2727
/**
2828
* <tt>EndpointCallback</tt> is a callback function for a message being sent. It invokes the endpoint function
2929
* specified
@@ -52,11 +52,12 @@ public EndpointCallback(final Object genericSvc, final Method method) {
5252
* @param message
5353
* - the message
5454
*/
55+
@Override
5556
@SuppressWarnings("unchecked")
5657
public void callback(final Message message) {
5758
final List<Object> parms = message.get(List.class, "MethodParms");
5859

59-
if ((parms == null && targetTypes.length != 0) || (parms.size() != targetTypes.length)) {
60+
if ((parms == null && targetTypes.length != 0) || (parms != null && parms.size() != targetTypes.length)) {
6061
throw new MessageDeliveryFailure("wrong number of arguments sent to endpoint. (received: "
6162
+ (parms == null ? 0 : parms.size()) + "; required: " + targetTypes.length + ")");
6263
}
@@ -78,7 +79,7 @@ else if (parms != null) {
7879
try {
7980
method.invoke(genericSvc, parms);
8081
}
81-
catch (Exception e) {
82+
catch (final Exception e) {
8283
throw new MessageDeliveryFailure("error invoking endpoint", e);
8384
}
8485
}

errai-bus/src/main/java/org/jboss/errai/bus/server/io/buffers/TransmissionBuffer.java

Lines changed: 33 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616

1717
package org.jboss.errai.bus.server.io.buffers;
1818

19-
import org.jboss.errai.bus.server.io.ByteWriteAdapter;
20-
2119
import java.io.IOException;
2220
import java.io.InputStream;
2321
import java.io.PrintWriter;
@@ -28,6 +26,8 @@
2826
import java.util.concurrent.atomic.AtomicLong;
2927
import java.util.concurrent.locks.ReentrantLock;
3028

29+
import org.jboss.errai.bus.server.io.ByteWriteAdapter;
30+
3131
/**
3232
* A ring-based buffer implementation that provides contention-free writing of <i>1..n</i> colors. In this case,
3333
* colors refer to the unique attribute that separates one topic of data from another. Global data, which is visible
@@ -244,8 +244,12 @@ public void write(final int writeSize,
244244
headSequence = writeHead + allocSize;
245245
}
246246
finally {
247-
bufferColor.wake();
248-
lock.unlock();
247+
try {
248+
bufferColor.wake();
249+
}
250+
finally {
251+
lock.unlock();
252+
}
249253
}
250254
}
251255

@@ -263,31 +267,36 @@ public void write(final int writeSize,
263267
*/
264268
@Override
265269
public boolean read(final ByteWriteAdapter outputStream, final BufferColor bufferColor) throws IOException {
266-
// obtain this color's read lock
267-
bufferColor.lock.lock();
270+
long lastSeq = -1l;
271+
272+
try {
273+
// obtain this color's read lock
274+
bufferColor.lock.lock();
268275

269-
// get the current head position.
270-
final long writeHead = headSequence;
276+
// get the current head position.
277+
final long writeHead = headSequence;
271278

272-
// get the tail position for the color.
273-
long read = bufferColor.sequence.get();
274-
long lastSeq = read;
279+
// get the tail position for the color.
280+
long read = bufferColor.sequence.get();
281+
lastSeq = read;
275282

276-
// checkOverflow(read);
283+
// checkOverflow(read);
277284

278-
try {
279285
while ((read = readNextChunk(writeHead, read, bufferColor, outputStream, null)) != -1)
280286
lastSeq = read;
281287

282288
return lastSeq != read;
283289
}
284290
finally {
291+
try {
285292
// move the tail sequence for this color up.
286293
if (lastSeq != -1)
287294
bufferColor.sequence.set(lastSeq);
288-
289-
// release the read lock on this color/
290-
bufferColor.lock.unlock();
295+
}
296+
finally {
297+
// release the read lock on this color/
298+
bufferColor.lock.unlock();
299+
}
291300
}
292301
}
293302

@@ -413,7 +422,7 @@ public boolean readWait(final ByteWriteAdapter outputStream,
413422
// lets wait for some data to come available
414423
bufferColor.dataWaiting.await();
415424
}
416-
catch (InterruptedException e) {
425+
catch (final InterruptedException e) {
417426
// if there's another reader contending, they should probably know about this.
418427
bufferColor.dataWaiting.signal();
419428
throw e;
@@ -479,7 +488,7 @@ public boolean readWait(final TimeUnit unit,
479488
// wait around for some data.
480489
nanos = bufferColor.dataWaiting.awaitNanos(nanos);
481490
}
482-
catch (InterruptedException e) {
491+
catch (final InterruptedException e) {
483492
bufferColor.dataWaiting.signal();
484493
throw e;
485494
}
@@ -566,7 +575,7 @@ public boolean readWait(final TimeUnit unit,
566575
try {
567576
nanos = bufferColor.dataWaiting.awaitNanos(nanos);
568577
}
569-
catch (InterruptedException e) {
578+
catch (final InterruptedException e) {
570579
bufferColor.dataWaiting.signal();
571580
throw e;
572581
}
@@ -712,10 +721,10 @@ private long readNextChunk(final long head,
712721
* @return the size in bytes.
713722
*/
714723
private int readChunkSize(final int position) {
715-
return ((((int) _buffer.get(position + 3)) & 0xFF)) +
716-
((((int) _buffer.get(position + 2)) & 0xFF) << 8) +
717-
((((int) _buffer.get(position + 1)) & 0xFF) << 16) +
718-
((((int) _buffer.get(position)) & 0xFF) << 24);
724+
return (((_buffer.get(position + 3)) & 0xFF)) +
725+
(((_buffer.get(position + 2)) & 0xFF) << 8) +
726+
(((_buffer.get(position + 1)) & 0xFF) << 16) +
727+
(((_buffer.get(position)) & 0xFF) << 24);
719728
}
720729

721730
private void writeChunkSize(final int position, final int size) {
@@ -741,7 +750,7 @@ public void dumpSegments(final PrintWriter writer) {
741750
int pos = i * segmentSize;
742751
int length = readChunkSize(pos);
743752
build.append("Segment ").append(i).append(" <color:")
744-
.append((int) segmentMap[i]).append(";length:").append(length)
753+
.append(segmentMap[i]).append(";length:").append(length)
745754
.append(";location:").append(pos).append(">");
746755

747756
pos += SEGMENT_HEADER_SIZE;
@@ -765,7 +774,6 @@ public void dumpSegments(final PrintWriter writer) {
765774
}
766775
}
767776

768-
@SuppressWarnings("UnusedDeclaration")
769777
public List<String> dumpSegmentsAsList() {
770778
final List<String> list = new ArrayList<String>();
771779

0 commit comments

Comments
 (0)