Skip to content

Commit

Permalink
errorprone :: AvoidObjectArrays
Browse files Browse the repository at this point in the history
  • Loading branch information
dev-mlb committed Oct 27, 2024
1 parent 76550b7 commit a4fa7a0
Show file tree
Hide file tree
Showing 17 changed files with 114 additions and 4 deletions.
20 changes: 20 additions & 0 deletions src/main/java/emissary/admin/PlaceStarter.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import javax.annotation.Nullable;

Expand Down Expand Up @@ -96,6 +97,7 @@ public static IServiceProviderPlace createPlace(final String theLocation, final
return createPlace(theLocation, constructorArgs, theClassStr);
}


/**
* Create a place using generic Object[] constructor args for maximum flexibility for finding any existing constructor.
* Will check to see if the place already exists first and return the existing instance from the Namespace if it does.
Expand All @@ -104,9 +106,27 @@ public static IServiceProviderPlace createPlace(final String theLocation, final
* @param constructorArgs array of args to pass to the place constructor
* @param theClassStr string name of the class to instantiate
* @return the place that was found or created, or null if it can't be done
* @deprecated use {@link #createPlace(String, List, String)}
*/
@Nullable
@Deprecated(forRemoval = true)
@SuppressWarnings("AvoidObjectArrays")
public static IServiceProviderPlace createPlace(final String theLocation, final Object[] constructorArgs, @Nullable final String theClassStr) {
return createPlace(theLocation, Arrays.asList(constructorArgs), theClassStr);
}

/**
* Create a place using generic List constructor args for maximum flexibility for finding any existing constructor. Will
* check to see if the place already exists first and return the existing instance from the Namespace if it does.
*
* @param theLocation key for the new place
* @param constructorArgs list of args to pass to the place constructor
* @param theClassStr string name of the class to instantiate
* @return the place that was found or created, or null if it can't be done
*/
@Nullable
public static IServiceProviderPlace createPlace(final String theLocation, final List<Object> constructorArgs,
@Nullable final String theClassStr) {
logger.debug("Ready to createPlace {} as {}", theLocation, theClassStr);

final long t1 = System.currentTimeMillis();
Expand Down
1 change: 1 addition & 0 deletions src/main/java/emissary/client/EmissaryResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.Arrays;
import javax.annotation.Nullable;

@SuppressWarnings("AvoidObjectArrays")
public class EmissaryResponse {

private static final Logger logger = LoggerFactory.getLogger(EmissaryResponse.class);
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/emissary/config/ConfigUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,10 @@ public static Configurator getConfigInfo(final Class<?> c) throws IOException {
* @param preferences array of string names to try
* @return the configurator
* @throws IOException if none of the prefs can be found
* @deprecated use {@link #getConfigInfo(List)}
*/
@Deprecated(forRemoval = true)
@SuppressWarnings("AvoidObjectArrays")
public static Configurator getConfigInfo(final String[] preferences) throws IOException {
return getConfigInfo(Arrays.asList(preferences));
}
Expand Down Expand Up @@ -510,6 +513,7 @@ public static List<String> getFlavors() {
* @param name the base resource or config name
* @return the name with the flavor in it
*/
@SuppressWarnings("AvoidObjectArrays")
public static String[] addFlavors(final String name) {
if (configFlavors == null || configFlavors.length() == 0) {
return new String[0];
Expand Down
20 changes: 20 additions & 0 deletions src/main/java/emissary/core/Factory.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,10 @@ public static Object create(final String className) {
* @param args the arguments to a public constructor of classname
* @param location name used to bind into the namespace
* @return the newly instantiated object
* @deprecated use {@link #create(String, List, String)}
*/
@Deprecated(forRemoval = true)
@SuppressWarnings("AvoidObjectArrays")
public static Object create(final String className, final Object[] args, final String location) {
if (logger.isDebugEnabled()) {
logger.debug("Factory.create(" + className + "," + Arrays.toString(args) + "," + location + ")");
Expand All @@ -125,6 +128,23 @@ public static Object create(final String className, final Object[] args, final S
return o;
}

/**
* Create an object and bind it into the namespace
*
* @param className the string classname to get a new instance of
* @param args the arguments to a public constructor of classname
* @param location name used to bind into the namespace
* @return the newly instantiated object
*/
public static Object create(final String className, final List<Object> args, final String location) {
if (logger.isDebugEnabled()) {
logger.debug("Factory.create({},{},{})", className, args, location);
}
final Object o = create(className, args.toArray());
Namespace.bind(location, o);
return o;
}

/**
* Create an object and bind it into the namespace. This method is used to prevent the ambiguity around overloaded
* varargs methods.
Expand Down
1 change: 1 addition & 0 deletions src/main/java/emissary/core/IMobileAgent.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ void arrive(Object payload, IServiceProviderPlace arrivalPlace, int mec, List<Di
*
* @return array of DirectoryEntry
*/
@SuppressWarnings("AvoidObjectArrays")
DirectoryEntry[] getItineraryQueueItems();

/**
Expand Down
1 change: 1 addition & 0 deletions src/main/java/emissary/jni/JNI.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
* wishing to loadLibraries from the JniRepositoryPlace should include this class via composition and invoke
* this.loadLibrary rather than System.loadLibrary()
*/
@SuppressWarnings("AvoidObjectArrays")
public class JNI implements Serializable {

static final long serialVersionUID = 3037911106823343480L;
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/emissary/kff/ChecksumCalculator.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public ChecksumCalculator() throws NoSuchAlgorithmException {
* @throws NoSuchAlgorithmException if the algorithm isn't available
*/
public ChecksumCalculator(String alg, boolean useCrc) throws NoSuchAlgorithmException {
this(new String[] {alg});
this(List.of(alg));
setUseCrc(useCrc);
}

Expand All @@ -59,6 +59,8 @@ public ChecksumCalculator(String alg, boolean useCrc) throws NoSuchAlgorithmExce
* @param algs array of String algorithm names, put CRC32 on list to enable
* @throws NoSuchAlgorithmException if an algorithm isn't available
*/
@Deprecated(forRemoval = true)
@SuppressWarnings("AvoidObjectArrays")
public ChecksumCalculator(@Nullable String[] algs) throws NoSuchAlgorithmException {
if (algs != null && algs.length > 0) {
for (String alg : algs) {
Expand Down
14 changes: 13 additions & 1 deletion src/main/java/emissary/output/DropOffPlace.java
Original file line number Diff line number Diff line change
Expand Up @@ -459,13 +459,25 @@ public List<IDropOffFilter> getFilters() {
* Provide access to filter names
*
* @return an array of filter names or an empty array if none
* @deprecated use {@link #getFilterNamesList()}
*/
@Deprecated(forRemoval = true)
@SuppressWarnings("AvoidObjectArrays")
public String[] getFilterNames() {
return getFilterNamesList().toArray(new String[0]);
}

/**
* Provide access to filter names
*
* @return a list of filter names or an empty list if none
*/
public List<String> getFilterNamesList() {
final List<String> fnames = new ArrayList<>();
for (final IDropOffFilter f : this.outputFilters) {
fnames.add(f.getFilterName());
}
return fnames.toArray(new String[0]);
return fnames;
}

/**
Expand Down
31 changes: 30 additions & 1 deletion src/main/java/emissary/output/DropOffUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.time.ZonedDateTime;
import java.time.format.DateTimeParseException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
Expand Down Expand Up @@ -493,8 +494,21 @@ public String getBestIdFrom(final IBaseDataObject d) {
* shortname. An ID = AUTO_GENERATED_ID will be ignored. If no id value is found, returns empty array.
*
* @return id
* @deprecated use {@link #getExistingIdsList(IBaseDataObject)}
*/
@Deprecated(forRemoval = true)
@SuppressWarnings("AvoidObjectArrays")
public String[] getExistingIds(final IBaseDataObject d) {
return getExistingIdsList(d).toArray(new String[0]);
}

/**
* Extract the ID from the payload. The ID from the payload is specified in the cfg file. An ID = SHORTNAME will use the
* shortname. An ID = AUTO_GENERATED_ID will be ignored. If no id value is found, returns empty list.
*
* @return a list of id values
*/
public List<String> getExistingIdsList(final IBaseDataObject d) {
final List<String> values = new ArrayList<>();
for (final String s : this.idTokens) {
if (!StringUtils.isBlank(d.getStringParameter(s))) {
Expand All @@ -508,7 +522,7 @@ public String[] getExistingIds(final IBaseDataObject d) {
}
}
}
return values.toArray(new String[0]);
return values;
}

public String getRootPath() {
Expand Down Expand Up @@ -941,8 +955,23 @@ public static List<String> getFullFilepathsFromParams(IBaseDataObject d) {
* @param d The IBDO
* @param filenameFields The list of fields on the IBDO to check
* @return The list of filenames found in the list of fields on the IBDO
* @deprecated use {@link #getFullFilepathsFromParams(IBaseDataObject, List)}
*/
@Deprecated(forRemoval = true)
@SuppressWarnings("AvoidObjectArrays")
public static List<String> getFullFilepathsFromParams(IBaseDataObject d, String[] filenameFields) {
return getFullFilepathsFromParams(d, Arrays.asList(filenameFields));
}

/**
* Uses the specified list of fields to check for filenames of the object. Returns a list with the non-empty strings
* found in these fields. If nothing is found in either field, return an empty list.
*
* @param d The IBDO
* @param filenameFields The list of fields on the IBDO to check
* @return The list of filenames found in the list of fields on the IBDO
*/
public static List<String> getFullFilepathsFromParams(IBaseDataObject d, List<String> filenameFields) {

List<String> filenames = new ArrayList<>();

Expand Down
13 changes: 12 additions & 1 deletion src/main/java/emissary/pickup/WorkSpace.java
Original file line number Diff line number Diff line change
Expand Up @@ -775,15 +775,26 @@ protected void addOutboundBundle(final WorkBundle wb) {

/**
* Show items that are pending completion (debug)
*
* @deprecated use {@link #showPendingItemsList()}
*/
@Deprecated(forRemoval = true)
@SuppressWarnings("AvoidObjectArrays")
public String[] showPendingItems() {
return showPendingItemsList().toArray(new String[0]);
}

/**
* Show items that are pending completion (debug)
*/
public List<String> showPendingItemsList() {
final List<String> list = new ArrayList<>();
synchronized (this.QLOCK) {
for (final Map.Entry<String, WorkBundle> entry : this.pending.entrySet()) {
list.add(entry.getValue().toString());
}
}
return list.toArray(new String[0]);
return list;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
/**
* Utilities for dealing with request parameters
*/
@SuppressWarnings("AvoidObjectArrays")
public class RequestUtil {
public static final int INT_PARAM_NOT_FOUND = -99;
public static final float FLOAT_PARAM_NOT_FOUND = -99.99f;
Expand Down
1 change: 1 addition & 0 deletions src/main/java/emissary/util/ConstructorLookupCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
* cache does not <i>guarantee</i> that it will be indefinitely cached or that the cached value will be visible to other
* threads.
*/
@SuppressWarnings("AvoidObjectArrays")
public final class ConstructorLookupCache {

private static final Logger logger = LoggerFactory.getLogger(ConstructorLookupCache.class);
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/emissary/util/DataUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,10 @@ public static String csvescape(final String field) {
* @param source to copy from
* @param target to copy to
* @param keys array of metadata keys to copy
* @deprecated use {@link #copyParams(IBaseDataObject, IBaseDataObject, Collection)}
*/
@Deprecated(forRemoval = true)
@SuppressWarnings("AvoidObjectArrays")
public static void copyParams(final IBaseDataObject source, final IBaseDataObject target, final String[] keys) {
for (final String k : keys) {
copyParam(source, target, k);
Expand Down
1 change: 1 addition & 0 deletions src/main/java/emissary/util/magic/MagicNumber.java
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,7 @@ private static byte[] getElement(@Nullable byte[] data, int offset, int length)
/**
* Add child continuations
*/
@SuppressWarnings("AvoidObjectArrays")
public void addDependencyLayer(MagicNumber[] dependencyLayer) {
if (dependencies == null) {
dependencies = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* @author ce
* @version 1.0
*/
@SuppressWarnings("AvoidObjectArrays")
public class BackwardsTreeScanner {

// The internal structure of the offset-keyword id array
Expand Down
1 change: 1 addition & 0 deletions src/main/java/emissary/util/search/FastBoyerMoore.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.util.List;
import javax.annotation.Nullable;

@SuppressWarnings("AvoidObjectArrays")
public class FastBoyerMoore {
private static final Logger logger = LoggerFactory.getLogger(FastBoyerMoore.class);
public byte[][] keywords;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package emissary.util.search;

@SuppressWarnings("AvoidObjectArrays")
public interface IMultiKeywordScanner {

void loadKeywords(String[] keywords);
Expand Down

0 comments on commit a4fa7a0

Please sign in to comment.