Skip to content

Commit

Permalink
Fix maven lint warnings
Browse files Browse the repository at this point in the history
* Fixes the lint warnings, mostly unchecked cast.
* Updates the maven-compiler-plugin, set release to 11, and source
  encoding to UTF-8
  • Loading branch information
jabolina committed Jan 1, 2024
1 parent 9a05186 commit 890bce5
Show file tree
Hide file tree
Showing 14 changed files with 37 additions and 27 deletions.
8 changes: 5 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
<description>JGroups RAFT implementation</description>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<maven.compiler.release>11</maven.compiler.release>

<!-- nexus-staging-maven-plugin -->
<autoReleaseAfterClose>true</autoReleaseAfterClose>
Expand Down Expand Up @@ -344,7 +346,7 @@
<goal>run</goal>
</goals>
<configuration>
<tasks>
<target>
<property name="compile_classpath" refid="maven.compile.classpath" />
<property name="plugin_classpath" refid="maven.plugin.classpath" />
<delete dir="${project.build.directory}/schema" failonerror="false" />
Expand All @@ -356,7 +358,7 @@
</classpath>
<arg line="-o ${project.build.directory}/schema" />
</java>
</tasks>
</target>
</configuration>
</execution>
</executions>
Expand Down Expand Up @@ -469,7 +471,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<version>3.12.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down
4 changes: 2 additions & 2 deletions src/org/jgroups/perf/CounterPerf.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ public void init(String props, String name, int bind_port, boolean use_fibers, S
System.out.println("Histogram enabled! Will be stored into " + histogramPath);
}
thread_factory=new DefaultThreadFactory("updater", false, true)
.useFibers(use_fibers);
if(use_fibers && Util.fibersAvailable())
.useVirtualThreads(use_fibers);
if(use_fibers && Util.virtualThreadsAvailable())
System.out.println("-- using fibers instead of threads");

channel=new JChannel(props).setName(name);
Expand Down
1 change: 0 additions & 1 deletion src/org/jgroups/protocols/raft/ELECTION.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ public class ELECTION extends BaseElection {
protected void handleView(View v) {
Majority result=Utils.computeMajority(view, v, raft().majority(), raft.leader());
log.debug("%s: existing view: %s, new view: %s, result: %s", local_addr, this.view, v, result);
System.out.printf("%s: existing view: %s, new view: %s, result: %s%n", local_addr, this.view, v, result);
List<Address> joiners=View.newMembers(this.view, v);
boolean has_new_members=joiners != null && !joiners.isEmpty();
this.view=v;
Expand Down
1 change: 1 addition & 0 deletions src/org/jgroups/protocols/raft/RAFT.java
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,7 @@ public long createNewTerm() {
return raft_state.advanceTermForElection();
}

@SuppressWarnings("unchecked")
public static <T> T findProtocol(Class<T> clazz, final Protocol start, boolean down) {
Protocol prot=start;
while(prot != null && clazz != null) {
Expand Down
10 changes: 1 addition & 9 deletions src/org/jgroups/protocols/raft/election/BaseElection.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public void resetStats() {

public void init() throws Exception {
super.init();
raft=findProtocol(RAFT.class);
raft=RAFT.findProtocol(RAFT.class, this, false);
}

public void stop() {
Expand Down Expand Up @@ -326,12 +326,4 @@ public synchronized BaseElection stopVotingThread() {
}
return this;
}

protected <T extends Protocol> T findProtocol(Class<T> clazz) {
for(Protocol p=up_prot; p != null; p=p.getUpProtocol()) {
if(clazz.isAssignableFrom(p.getClass()))
return (T)p;
}
throw new IllegalStateException(clazz.getSimpleName() + " not found above " + this.getClass().getSimpleName());
}
}
2 changes: 1 addition & 1 deletion src/org/jgroups/raft/blocks/ReplicatedStateMachine.java
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ protected V invoke(byte command, K key, V val, boolean ignore_return_value) thro

byte[] buf=out.buffer();
byte[] rsp=raft.set(buf, 0, out.position(), repl_timeout, TimeUnit.MILLISECONDS);
return ignore_return_value || rsp == null ? null: (V)Util.objectFromByteBuffer(rsp, 0, rsp.length, class_loader);
return ignore_return_value || rsp == null ? null: Util.objectFromByteBuffer(rsp, 0, rsp.length, class_loader);
}

protected void notifyPut(K key, V val, V old_val) {
Expand Down
8 changes: 4 additions & 4 deletions src/org/jgroups/raft/testfwk/PartitionedRaftCluster.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ public class PartitionedRaftCluster extends MockRaftCluster {
protected final Map<Address, RaftNode> nodes = new ConcurrentHashMap<>();

@Override
public PartitionedRaftCluster clear() {
public <T extends MockRaftCluster> T clear() {
nodes.clear();
return self();
}

@Override
public PartitionedRaftCluster add(Address addr, RaftNode node) {
public <T extends MockRaftCluster> T add(Address addr, RaftNode node) {
nodes.put(addr, node);
return this;
return self();
}

@Override
Expand Down Expand Up @@ -73,7 +73,7 @@ public int size() {
}

@Override
public PartitionedRaftCluster remove(Address addr) {
public <T extends MockRaftCluster> T remove(Address addr) {
nodes.remove(addr);
return self();
}
Expand Down
15 changes: 11 additions & 4 deletions src/org/jgroups/raft/testfwk/RaftCluster.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,23 @@ public class RaftCluster extends MockRaftCluster {
protected boolean async;

@Override
public RaftCluster add(Address addr, RaftNode node) {
public <T extends MockRaftCluster> T add(Address addr, RaftNode node) {
nodes.put(addr, node);
return this;
return self();
}

@Override
public RaftCluster remove(Address addr) {nodes.remove(addr); return this;}
public <T extends MockRaftCluster> T remove(Address addr) {
nodes.remove(addr);
return self();
}

@Override
public RaftCluster clear() {nodes.clear(); return this;}
public <T extends MockRaftCluster> T clear() {
nodes.clear();
return self();
}

public boolean dropTraffic() {return !dropped_members.isEmpty();}
public RaftCluster dropTrafficTo(Address a) {move(a, nodes, dropped_members); return this;}
public RaftCluster clearDroppedTrafficTo(Address a) {move(a, dropped_members, nodes); return this;}
Expand Down
1 change: 1 addition & 0 deletions src/org/jgroups/raft/testfwk/RaftNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ public String toString() {

}

@SuppressWarnings("unchecked")
protected <T extends Protocol> T find(Class<T> cl) {
for(Protocol p: prots) {
if(p.getClass().isAssignableFrom(cl))
Expand Down
1 change: 1 addition & 0 deletions src/org/jgroups/raft/util/AnalyzeLog.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public class AnalyzeLog {
protected Function<DataInput,String> snapshot_reader=CounterService::readAndDumpSnapshot;
protected PersistentState persistent_state;

@SuppressWarnings("unchecked")
public AnalyzeLog logClass(String cl) throws ClassNotFoundException {
log_class=(Class<? extends Log>)Class.forName(cl);
return this;
Expand Down
9 changes: 7 additions & 2 deletions src/org/jgroups/raft/util/ArrayRingBuffer.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public ArrayRingBuffer(final long headSequence) {
}

public ArrayRingBuffer(final int initialSize, final long headSequence) {
this.elements = (T[]) (initialSize == 0 ? EMPTY : new Object[initialSize]);
this.elements = allocate(initialSize);
this.headSequence = headSequence;
this.tailSequence = headSequence;
if (headSequence < 0) {
Expand Down Expand Up @@ -282,7 +282,7 @@ private void growCapacity(int delta) {
// see ArrayList::newCapacity
throw new OutOfMemoryError();
}
final T[] newElements = (T[]) new Object[newCapacity];
final T[] newElements = allocate(newCapacity);
final int size = size();
final long headSequence = this.headSequence;
long oldIndex = headSequence;
Expand All @@ -305,4 +305,9 @@ private void growCapacity(int delta) {
private static int findNextPositivePowerOfTwo(final int value) {
return 1 << (Integer.SIZE - Integer.numberOfLeadingZeros(value - 1));
}

@SuppressWarnings("unchecked")
private static <T> T[] allocate(int capacity) {
return (T[]) (capacity == 0 ? EMPTY : new Object[capacity]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public class SynchronousTests extends BaseRaftClusterTest<RaftCluster> {
}

@Override
@SuppressWarnings("unchecked")
protected void passDataProviderParameters(Object[] args) {
logClass = (Class<? extends Log>) args[0];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ private Address createAddress(String name) {
return ExtendedUUID.randomUUID(name).put(RAFT.raft_id_key, Util.stringToBytes(name));
}

@SuppressWarnings("unchecked")
private <P extends Protocol> P findProtocol(Protocol[] stack, Class<P> clazz) {
for (Protocol protocol : stack) {
if (clazz.isAssignableFrom(protocol.getClass()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ protected final T stateMachine(int index) {
* @param r: {@link RAFT} instance to retrieve the {@link StateMachine}.
* @return The {@link StateMachine} cast to type T.
*/
@SuppressWarnings("unchecked")
protected final T stateMachine(RAFT r) {
// noinspection unchecked
return (T) r.stateMachine();
}

Expand Down

0 comments on commit 890bce5

Please sign in to comment.