Skip to content

Commit

Permalink
Misc static bug analysis fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
johnou authored and kuujo committed Apr 9, 2018
1 parent 8759457 commit 0e0f945
Show file tree
Hide file tree
Showing 13 changed files with 31 additions and 22 deletions.
2 changes: 2 additions & 0 deletions core/src/test/java/io/atomix/core/AtomixTest.java
Expand Up @@ -15,6 +15,7 @@
*/
package io.atomix.core;

import com.google.common.base.Throwables;
import io.atomix.cluster.ClusterEvent;
import io.atomix.cluster.ClusterEventListener;
import io.atomix.cluster.Node;
Expand Down Expand Up @@ -230,6 +231,7 @@ public void onEvent(ClusterEvent event) {
try {
queue.put(event);
} catch (InterruptedException e) {
Throwables.propagate(e);
}
}

Expand Down
Expand Up @@ -411,7 +411,7 @@ private boolean stringArrayCollectionIsEqual(
* Entry comparator, uses both key and value to determine equality,
* for comparison falls back to the default string comparator.
*/
private class EntryComparator implements Comparator<Map.Entry<String, String>> {
private static class EntryComparator implements Comparator<Map.Entry<String, String>> {

@Override
public int compare(Map.Entry<String, String> o1, Map.Entry<String, String> o2) {
Expand Down
Expand Up @@ -300,7 +300,7 @@ public void testClear() throws Exception {
/**
* Tests listeners.
*/
@Test
@Test(timeout = 45000)
public void testNotifications() throws Exception {
AsyncDocumentTree<String> tree = newTree(UUID.randomUUID().toString());
TestEventListener listener = new TestEventListener();
Expand Down Expand Up @@ -334,7 +334,7 @@ public void testNotifications() throws Exception {
assertEquals("xy", event.newValue().get().value());
}

@Test
@Test(timeout = 45000)
public void testFilteredNotifications() throws Throwable {
String treeName = UUID.randomUUID().toString();
AsyncDocumentTree<String> tree1 = newTree(treeName);
Expand Down
Expand Up @@ -83,7 +83,7 @@ public PrimaryBackupServerContext(
* @return the current server role
*/
public Role getRole() {
return Objects.equals(primaryElection.getTerm().join().primary(), clusterService.getLocalNode().id())
return Objects.equals(primaryElection.getTerm().join().primary().nodeId(), clusterService.getLocalNode().id())
? Role.PRIMARY
: Role.BACKUP;
}
Expand Down
Expand Up @@ -205,7 +205,7 @@ private void changeReplicas(PrimaryTerm term) {
* Handles a cluster event.
*/
private void handleClusterEvent(ClusterEvent event) {
if (event.type() == ClusterEvent.Type.NODE_DEACTIVATED && event.subject().id().equals(term.primary())) {
if (event.type() == ClusterEvent.Type.NODE_DEACTIVATED && event.subject().id().equals(term.primary().nodeId())) {
threadContext.execute(() -> {
state = State.SUSPENDED;
stateChangeListeners.forEach(l -> l.accept(state));
Expand Down
Expand Up @@ -349,7 +349,11 @@ protected void sendConfigureRequest(RaftMemberContext member, ConfigureRequest r
log.trace("Received {} from {}", response, member.getMember().nodeId());
handleConfigureResponse(member, request, response, timestamp);
} else {
log.warn("Failed to configure {}", member.getMember().nodeId());
if (log.isTraceEnabled()) {
log.warn("Failed to configure {}", member.getMember().nodeId(), error);
} else {
log.warn("Failed to configure {}", member.getMember().nodeId());
}
handleConfigureResponseFailure(member, request, error);
}
}
Expand Down
Expand Up @@ -146,7 +146,7 @@ protected SnapshotReader openReader(SnapshotReader reader, SnapshotDescriptor de
* Closes the current snapshot reader.
*/
protected void closeReader(SnapshotReader reader) {
reader = null;

}

/**
Expand Down Expand Up @@ -202,11 +202,9 @@ public int hashCode() {

@Override
public boolean equals(Object object) {
if (getClass() == object.getClass()) {
Snapshot snapshot = (Snapshot) object;
return snapshot.index() == index();
}
return false;
if (object == null || getClass() != object.getClass()) return false;
Snapshot snapshot = (Snapshot) object;
return snapshot.index() == index();
}

@Override
Expand Down
Expand Up @@ -125,7 +125,11 @@ public synchronized void storeConfiguration(Configuration configuration) {
*/
public synchronized Configuration loadConfiguration() {
if (configurationBuffer.position(0).readByte() == 1) {
return serializer.decode(configurationBuffer.readBytes(configurationBuffer.readInt()));
int bytesLength = configurationBuffer.readInt();
if (bytesLength == 0) {
throw new IllegalStateException("Bytes length equal to zero");
}
return serializer.decode(configurationBuffer.readBytes(bytesLength));
}
return null;
}
Expand Down
Expand Up @@ -103,7 +103,7 @@ private RaftSession createSession(long sessionId) {
mock(ThreadContextFactory.class));
}

private class TestSessionListener implements SessionListener {
private static class TestSessionListener implements SessionListener {
private final BlockingQueue<String> queue = new ArrayBlockingQueue<>(1);

@Override
Expand Down
6 changes: 3 additions & 3 deletions storage/src/main/java/io/atomix/storage/buffer/FileBytes.java
Expand Up @@ -249,15 +249,15 @@ public Bytes read(int position, Bytes bytes, int offset, int length) {
if (bytes.hasArray()) {
try {
seekToOffset(position);
randomAccessFile.read(bytes.array(), (int) offset, (int) length);
randomAccessFile.readFully(bytes.array(), (int) offset, (int) length);
} catch (IOException e) {
throw new RuntimeException(e);
}
} else {
try {
seekToOffset(position);
byte[] readBytes = new byte[(int) length];
randomAccessFile.read(readBytes);
randomAccessFile.readFully(readBytes);
bytes.write(offset, readBytes, 0, length);
} catch (IOException e) {
throw new RuntimeException(e);
Expand All @@ -271,7 +271,7 @@ public Bytes read(int position, byte[] bytes, int offset, int length) {
checkRead(position, length);
try {
seekToOffset(position);
randomAccessFile.read(bytes, (int) offset, (int) length);
randomAccessFile.readFully(bytes, (int) offset, (int) length);
} catch (IOException e) {
throw new RuntimeException(e);
}
Expand Down
Expand Up @@ -539,8 +539,9 @@ else if (previousSegment.index() + previousSegment.length() > segment.index()) {
}
}

for (Long segmentId : segments.keySet()) {
JournalSegment<E> segment = segments.get(segmentId);
for (Map.Entry<Long, JournalSegment<E>> entry : segments.entrySet()) {
final Long segmentId = entry.getKey();
final JournalSegment<E> segment = entry.getValue();
Map.Entry<Long, JournalSegment<E>> previousEntry = segments.floorEntry(segmentId - 1);
if (previousEntry != null) {
JournalSegment<E> previousSegment = previousEntry.getValue();
Expand Down
2 changes: 1 addition & 1 deletion utils/src/test/java/io/atomix/utils/GenericsTest.java
Expand Up @@ -39,7 +39,7 @@ public interface GenericInterface<T1, T2> {
T2 type2();
}

public class ConcreteInterface implements GenericInterface<String, SomeClass> {
public static class ConcreteInterface implements GenericInterface<String, SomeClass> {
@Override
public String type1() {
return null;
Expand Down
Expand Up @@ -84,9 +84,9 @@ private String failCompletely(String input) {
}
}

private class RetryableException extends RuntimeException {
private static class RetryableException extends RuntimeException {
}

private class NonRetryableException extends RuntimeException {
private static class NonRetryableException extends RuntimeException {
}
}

0 comments on commit 0e0f945

Please sign in to comment.