Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

errorprone :: JDKObsolete Fix #755

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/main/java/emissary/core/MobileAgent.java
Expand Up @@ -16,8 +16,8 @@
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;

import java.util.ArrayList;
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 +81,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 ArrayList<DirectoryEntry> nextKeyQueue = new ArrayList<>();

// Track moveErrors on all parts of a given payload
protected int moveErrorsOccurred = 0;
Expand Down Expand Up @@ -449,7 +449,7 @@ protected DirectoryEntry getNextKey(@Nullable final IServiceProviderPlace place,
// choose the next one and spit it out
if (!this.nextKeyQueue.isEmpty()) {
logger.debug("Returning next key from stack size={}", this.nextKeyQueue.size());
return this.nextKeyQueue.removeFirst();
return this.nextKeyQueue.remove(0);
}

// We would need a current form of the payload to continue
Expand Down Expand Up @@ -623,7 +623,7 @@ protected DirectoryEntry nextKeyFromDirectory(final String dataId, final IServic
// Dequeue first item and return it to the caller
DirectoryEntry tmpEntry = null;
if (!this.nextKeyQueue.isEmpty()) {
tmpEntry = this.nextKeyQueue.removeFirst();
tmpEntry = this.nextKeyQueue.remove(0);
}
logger.debug("nextKeyFromDirectory found {}", tmpEntry);
return tmpEntry;
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/emissary/kff/KffMemcached.java
Expand Up @@ -13,8 +13,7 @@

import java.io.IOException;
import java.net.InetSocketAddress;
import java.util.LinkedList;
import java.util.List;
import java.util.ArrayList;
import java.util.Set;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -135,7 +134,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<>();
ArrayList<InetSocketAddress> servers = new ArrayList<>();
for (String serverFromConfig : serversFromConfig) {
// Transform to an InetSocketAddress
if (serverFromConfig.contains(":")) {
Expand Down
Expand Up @@ -7,8 +7,7 @@
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.ArrayList;
import java.util.UUID;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock;
Expand All @@ -28,7 +27,7 @@ public class JournaledChannelPool implements AutoCloseable {
final int max;
final Path directory;
final String key;
private final Queue<JournaledChannel> free = new LinkedList<>();
private final ArrayList<JournaledChannel> free = new ArrayList<>();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar comment here on use of ArrayList vs ArrayDeque

private int created;
@Nullable
private JournaledChannel[] allchannels;
Expand Down Expand Up @@ -95,7 +94,7 @@ void free(final JournaledChannel jc) {
}
this.lock.lock();
try {
if (this.free.contains(jc) || !this.free.offer(jc)) {
if (this.free.contains(jc) || !this.free.add(jc)) {
LOG.warn("Could not return the channel to the pool {}", this.key);
}
// signal everyone since close and find may be waiting
Expand Down Expand Up @@ -135,8 +134,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 All @@ -145,7 +144,7 @@ private JournaledChannel findFree() throws InterruptedException, IOException {
checkClosed();
}
}
return this.free.poll();
return this.free.remove(0);
}

private void createChannel() throws IOException {
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/emissary/pickup/PickupQueue.java
Expand Up @@ -3,15 +3,15 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.LinkedList;
import java.util.ArrayList;
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 ArrayList<WorkBundle> queue = new ArrayList<>();

// Our logger
private static final Logger logger = LoggerFactory.getLogger(PickupQueue.class);
Expand Down Expand Up @@ -96,7 +96,7 @@ public synchronized WorkBundle deque() {
synchronized (queue) {
size = queue.size();
if (size > 0) {
nextFile = queue.removeLast();
nextFile = queue.remove(size - 1);
}
}
return nextFile;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/emissary/pickup/QueServer.java
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
8 changes: 4 additions & 4 deletions src/main/java/emissary/pool/MoveSpool.java
Expand Up @@ -12,9 +12,9 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import javax.annotation.Nullable;
Expand All @@ -31,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 ArrayList<SpoolItem> spool = new ArrayList<>();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why use ArrayList here vs ArrayDeque? Performance isn't much of a concern based on possible sizes, so both are probably sufficient, but ArrayDeque has a nicer interface for operating on both ends and might be closer to the intent of the spool?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why use ArrayList here vs ArrayDeque? Performance isn't much of a concern based on possible sizes, so both are probably sufficient, but ArrayDeque has a nicer interface for operating on both ends and might be closer to the intent of the spool?

Because these resolutions were auto-generated by errorprone.


// Reference to the agent pool
protected AgentPool pool;
Expand Down Expand Up @@ -250,7 +250,7 @@ protected SpoolItem removeFirstPayload() {
highWaterMark = spool.size();
}

s = spool.removeFirst();
s = spool.remove(0);
dequeCount++;
}
return s;
Expand Down Expand Up @@ -312,7 +312,7 @@ protected int enqueue(Method method, Object payload, @Nullable IServiceProviderP
int size = 0;

synchronized (spool) {
spool.addLast(s);
spool.add(s);
enqueCount++;
size = spool.size();
spool.notifyAll();
Expand Down
7 changes: 3 additions & 4 deletions src/main/java/emissary/server/mvc/DumpDirectoryAction.java
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<>();
ArrayList<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<>();
ArrayList<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<>();
ArrayList<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
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
20 changes: 10 additions & 10 deletions src/main/java/emissary/util/io/FileFind.java
Expand Up @@ -9,9 +9,9 @@
import java.io.File;
import java.io.FileFilter;
import java.io.IOException;
import java.util.ArrayDeque;
import java.util.Iterator;
import java.util.NoSuchElementException;
import java.util.Stack;
import javax.annotation.Nullable;

/**
Expand Down Expand Up @@ -91,7 +91,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 ArrayDeque<Object> currentPath = new ArrayDeque<>();
@Nullable
private FileFilter filter = null;

Expand All @@ -104,7 +104,7 @@ public FileIterator(String filename, FileFilter filter) throws IOException {
if (!f.exists() || !f.canRead()) {
throw new IOException("File not Found:" + filename);
}
currentPath.push(f);
currentPath.addFirst(f);
this.filter = filter;
findNextFile();
}
Expand All @@ -121,7 +121,7 @@ public boolean hasNext() {
@Override
public Object next() {
if (!currentPath.isEmpty()) {
Object tmp = currentPath.pop();
Object tmp = currentPath.removeFirst();
findNextFile();
return tmp;
}
Expand All @@ -140,31 +140,31 @@ private void findNextFile() {
boolean found = false;
// While the stack is not empty, and we have not found the type of file that we are looking for.
while (!currentPath.isEmpty() && !found) {
Object tmp = currentPath.peek();
Object tmp = currentPath.peekFirst();
if (tmp instanceof File && !((File) tmp).isDirectory()) {
// We found one. Leave it on the stack for 'next()'
found = true;
} else if (tmp instanceof File && ((File) tmp).isDirectory()) {

// Pop the entry for the directory name if not desired
Object theDir = currentPath.pop();
Object theDir = currentPath.removeFirst();

// Add the directory contents to the stack
File[] tmpContents = ((File) tmp).listFiles(filter);
currentPath.push(new DirectoryList(tmpContents));
currentPath.addFirst(new DirectoryList(tmpContents));

// Put back the directory if we are supposed to return thm
if (wantDirectories) {
currentPath.push(theDir);
currentPath.addFirst(theDir);
found = true;
}

} else if (tmp instanceof DirectoryList) {
// This is a directories contents. Check for the next entry.
if (((DirectoryList) tmp).hasNext()) {
currentPath.push(((DirectoryList) tmp).next());
currentPath.addFirst(((DirectoryList) tmp).next());
} else {
currentPath.pop();
currentPath.removeFirst();
}
}
}
Expand Down
30 changes: 15 additions & 15 deletions src/main/java/emissary/util/magic/MagicMath.java
@@ -1,10 +1,10 @@
package emissary.util.magic;

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

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

public static byte[] parseEscapedString(String s) {
List<Number> array = new ArrayList<>();
Stack<Character> chars = new Stack<>();
ArrayDeque<Character> chars = new ArrayDeque<>();
for (int i = (s.length() - 1); i >= 0; i--) {
chars.push(s.charAt(i));
chars.addFirst(s.charAt(i));
}
while (!chars.empty()) {
Character c = chars.pop();
while (!chars.isEmpty()) {
Character c = chars.removeFirst();
String val = EMPTYSTRING;
if (c == '\\') {
if (chars.empty()) {
if (chars.isEmpty()) {
array.add(32);
break;
}
Character next = chars.peek();
Character next = chars.peekFirst();
if (literals[next] > 0) {
array.add(literals[next]);
chars.pop();
chars.removeFirst();
} else if (Character.isDigit(next)) {
int max = 3;
while (!chars.empty() && Character.isDigit(next) && max-- > 0) {
val += chars.pop();
if (!chars.empty()) {
next = chars.peek();
while (!chars.isEmpty() && Character.isDigit(next) && max-- > 0) {
val += chars.removeFirst();
if (!chars.isEmpty()) {
next = chars.peekFirst();
}
}
array.add(new BigInteger(val, 8));
val = EMPTYSTRING;
} else if (next == 'x') {
chars.pop(); // pop the hex symbol
val += chars.pop();
val += chars.pop();
chars.removeFirst(); // pop the hex symbol
val += chars.removeFirst();
val += chars.removeFirst();
array.add(new BigInteger(val, 16));
val = EMPTYSTRING;
}
Expand Down