Skip to content

Commit

Permalink
errorprone :: JDKObsolete Fix (#755)
Browse files Browse the repository at this point in the history
  • Loading branch information
nixon124 committed Jun 5, 2024
1 parent ce78584 commit ff7d52f
Show file tree
Hide file tree
Showing 12 changed files with 45 additions and 40 deletions.
5 changes: 3 additions & 2 deletions src/main/java/emissary/core/MobileAgent.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;

import java.util.ArrayDeque;
import java.util.Deque;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;
Expand Down Expand Up @@ -81,7 +82,7 @@ public abstract class MobileAgent implements IMobileAgent, MobileAgentMBean {
protected transient volatile boolean timeToQuit = false;

// Queue of DirectoryEntry keys to be processed
protected LinkedList<DirectoryEntry> nextKeyQueue = new LinkedList<>();
protected Deque<DirectoryEntry> nextKeyQueue = new ArrayDeque<>();

// Track moveErrors on all parts of a given payload
protected int moveErrorsOccurred = 0;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/emissary/kff/KffMemcached.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

import java.io.IOException;
import java.net.InetSocketAddress;
import java.util.LinkedList;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.concurrent.Future;
Expand Down Expand Up @@ -135,7 +135,7 @@ public KffMemcached(String testIdWithSpaces, String filterName, FilterType dupli

// Load up the list of servers
Set<String> serversFromConfig = configG.findEntriesAsSet("MEMCACHED_SERVER");
List<InetSocketAddress> servers = new LinkedList<>();
List<InetSocketAddress> servers = new ArrayList<>();
for (String serverFromConfig : serversFromConfig) {
// Transform to an InetSocketAddress
if (serverFromConfig.contains(":")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import java.nio.channels.ClosedChannelException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.LinkedList;
import java.util.Queue;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.UUID;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock;
Expand All @@ -28,7 +28,7 @@ public class JournaledChannelPool implements AutoCloseable {
final int max;
final Path directory;
final String key;
private final Queue<JournaledChannel> free = new LinkedList<>();
private final Deque<JournaledChannel> free = new ArrayDeque<>();
private int created;
@Nullable
private JournaledChannel[] allchannels;
Expand Down Expand Up @@ -135,8 +135,8 @@ private void checkClosed() throws ClosedChannelException {
}

private JournaledChannel findFree() throws InterruptedException, IOException {
// if nothing is available and we can create additional channels, do it
// clould get closed when we await
// if nothing is available, and we can create additional channels, do it
// could get closed when we await
while (this.free.isEmpty()) {
if (this.created < this.max) {
createChannel();
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/emissary/pickup/PickupQueue.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.LinkedList;
import java.util.ArrayDeque;
import java.util.Deque;
import javax.annotation.Nullable;

/**
* A size limited queue for holding data to process.
*/
public class PickupQueue {
// Data structure for the bundles
protected final LinkedList<WorkBundle> queue = new LinkedList<>();
protected final Deque<WorkBundle> queue = new ArrayDeque<>();

// Our logger
private static final Logger logger = LoggerFactory.getLogger(PickupQueue.class);
Expand Down Expand Up @@ -53,7 +54,7 @@ public boolean enque(@Nullable WorkBundle paths) {

synchronized (queue) {
// Add it to the queue
queue.add(0, paths);
queue.addFirst(paths);
queue.notifyAll();
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/emissary/pickup/QueServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public void checkQue() {
logger.debug("Initiating bundle completed msg for {}, status={}", paths.getBundleId(), status);
space.bundleCompleted(paths.getBundleId(), status);
} catch (Exception e) {
StringBuffer fnb = new StringBuffer();
StringBuilder fnb = new StringBuilder();
// Report filenames on error
for (Iterator<String> i = paths.getFileNameIterator(); i.hasNext();) {
String fn = i.next();
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/emissary/pool/MoveSpool.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayDeque;
import java.util.Deque;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import javax.annotation.Nullable;
Expand All @@ -30,7 +31,7 @@ public class MoveSpool implements Runnable {
private static final Logger logger = LoggerFactory.getLogger(MoveSpool.class);

// The payload FIFO
protected final LinkedList<SpoolItem> spool = new LinkedList<>();
protected final Deque<SpoolItem> spool = new ArrayDeque<>();

// Reference to the agent pool
protected AgentPool pool;
Expand Down
7 changes: 3 additions & 4 deletions src/main/java/emissary/server/mvc/DumpDirectoryAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import javax.annotation.Nullable;
Expand Down Expand Up @@ -69,13 +68,13 @@ public Map<String, Object> dumpDirectory(@Context HttpServletRequest request, @N
}

int rowCount = 0;
List<DirectoryInfo> entryKeys = new LinkedList<>();
List<DirectoryInfo> entryKeys = new ArrayList<>();
long now = System.currentTimeMillis();

if (dir != null) {
for (String dataId : dir.getEntryKeys()) {
LOG.trace("dataId key is {}", dataId);
List<DirectoryEntryInfo> list = new LinkedList<>();
List<DirectoryEntryInfo> list = new ArrayList<>();
for (DirectoryEntry entry : dir.getEntryList(dataId)) {
LOG.trace("Found entry {}", entry);
list.add(new DirectoryEntryInfo(rowCount++ % 2 == 0 ? "even" : "odd", entry, now));
Expand All @@ -90,7 +89,7 @@ public Map<String, Object> dumpDirectory(@Context HttpServletRequest request, @N
LOG.debug("Found no entry keys");
}

List<PeerInfo> peers = new LinkedList<>();
List<PeerInfo> peers = new ArrayList<>();
if (dir != null) {
for (String peerkey : dir.getPeerDirectories()) {
peers.add(new PeerInfo(peerkey, dir.isRemoteDirectoryAvailable(peerkey)));
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/emissary/util/MagicNumberUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ public String getErrorLog() {
*/
public String getErrorLog(final List<MagicNumber> magicNumberList, final List<String> zeroDepthErrorList,
final Map<String, List<String>> continuationErrorMap) {
final StringBuffer sb = new StringBuffer();
final StringBuilder sb = new StringBuilder();
final String lineBreak = "\n###########################################################";
sb.append(lineBreak);
sb.append("\nSUMMARY");
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/emissary/util/io/FileFind.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
import java.io.File;
import java.io.FileFilter;
import java.io.IOException;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Iterator;
import java.util.NoSuchElementException;
import java.util.Stack;
import javax.annotation.Nullable;

/**
Expand Down Expand Up @@ -91,7 +92,7 @@ class FileIterator implements Iterator {
/**
* Stack of Files and directory lists keeping track of where in the tree we are.
*/
private Stack<Object> currentPath = new Stack<>();
private Deque<Object> currentPath = new ArrayDeque<>();
@Nullable
private FileFilter filter = null;

Expand Down
13 changes: 7 additions & 6 deletions src/main/java/emissary/util/magic/MagicMath.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package emissary.util.magic;

import java.math.BigInteger;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Deque;
import java.util.Iterator;
import java.util.List;
import java.util.Stack;
import javax.annotation.Nullable;

public class MagicMath {
Expand Down Expand Up @@ -55,15 +56,15 @@ public static String byteArrayToHexString(byte[] b) {

public static byte[] parseEscapedString(String s) {
List<Number> array = new ArrayList<>();
Stack<Character> chars = new Stack<>();
Deque<Character> chars = new ArrayDeque<>();
for (int i = (s.length() - 1); i >= 0; i--) {
chars.push(s.charAt(i));
}
while (!chars.empty()) {
while (!chars.isEmpty()) {
Character c = chars.pop();
String val = EMPTYSTRING;
if (c == '\\') {
if (chars.empty()) {
if (chars.isEmpty()) {
array.add(32);
break;
}
Expand All @@ -73,9 +74,9 @@ public static byte[] parseEscapedString(String s) {
chars.pop();
} else if (Character.isDigit(next)) {
int max = 3;
while (!chars.empty() && Character.isDigit(next) && max-- > 0) {
while (!chars.isEmpty() && Character.isDigit(next) && max-- > 0) {
val += chars.pop();
if (!chars.empty()) {
if (!chars.isEmpty()) {
next = chars.peek();
}
}
Expand Down
19 changes: 10 additions & 9 deletions src/main/java/emissary/util/magic/MagicNumber.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
import org.slf4j.LoggerFactory;

import java.io.UnsupportedEncodingException;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Deque;
import java.util.List;
import java.util.Stack;
import javax.annotation.Nullable;

public class MagicNumber {
Expand Down Expand Up @@ -169,16 +170,16 @@ private String format(String desc, byte[] data) {
if (!substitute) {
return desc;
}
Stack<Character> stack = new Stack<>();
Deque<Character> chars = new ArrayDeque<>();
for (int i = (desc.length() - 1); i >= 0; --i) {
stack.push(desc.charAt(i));
chars.push(desc.charAt(i));
}
StringBuilder sb = new StringBuilder();

while (!stack.empty()) {
Character next = stack.pop();
if (!stack.empty() && next.charValue() == '%') {
Character subType = stack.pop();
while (!chars.isEmpty()) {
Character next = chars.pop();
if (!chars.isEmpty() && next.charValue() == '%') {
Character subType = chars.pop();
try {
if (dataType == TYPE_STRING) {
if (offset < (data.length - 2)) {
Expand All @@ -204,8 +205,8 @@ private String format(String desc, byte[] data) {
} catch (UnsupportedEncodingException e) {
throw new IllegalArgumentException(e);
}
if (subType.charValue() == 'l' && !stack.empty() && stack.peek().charValue() == 'd') {
stack.pop();
if (subType.charValue() == 'l' && !chars.isEmpty() && chars.peek().charValue() == 'd') {
chars.pop();
}
continue;
}
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/emissary/util/shell/ExecutrixTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,8 @@ void testExecute() throws IOException {
logger.debug("Command to exec is " + Arrays.asList(c));

int pstat;
final StringBuffer out = new StringBuffer();
final StringBuffer err = new StringBuffer();
final StringBuilder out = new StringBuilder();
final StringBuilder err = new StringBuilder();

pstat = e.execute(c, out, err);
logger.debug("Stdout: " + out);
Expand All @@ -299,7 +299,7 @@ void testExecute() throws IOException {
assertTrue(pstat >= 0, "Process return value");
readAndNuke(names[Executrix.OUTPATH]);

pstat = e.execute(c, out, "UTF-8");
pstat = e.execute(c, out, new StringBuilder("UTF-8"));
assertTrue(pstat >= 0, "Process return value");
readAndNuke(names[Executrix.OUTPATH]);

Expand Down

0 comments on commit ff7d52f

Please sign in to comment.