From a4fa7a00d23186ebc5228dd18f20af8824fd2daa Mon Sep 17 00:00:00 2001 From: dev-mlb <19797865+dev-mlb@users.noreply.github.com> Date: Tue, 22 Oct 2024 15:06:56 -0400 Subject: [PATCH] errorprone :: AvoidObjectArrays --- .../java/emissary/admin/PlaceStarter.java | 20 ++++++++++++ .../emissary/client/EmissaryResponse.java | 1 + src/main/java/emissary/config/ConfigUtil.java | 4 +++ src/main/java/emissary/core/Factory.java | 20 ++++++++++++ src/main/java/emissary/core/IMobileAgent.java | 1 + src/main/java/emissary/jni/JNI.java | 1 + .../java/emissary/kff/ChecksumCalculator.java | 4 ++- .../java/emissary/output/DropOffPlace.java | 14 ++++++++- .../java/emissary/output/DropOffUtil.java | 31 ++++++++++++++++++- src/main/java/emissary/pickup/WorkSpace.java | 13 +++++++- .../server/mvc/adapters/RequestUtil.java | 1 + .../emissary/util/ConstructorLookupCache.java | 1 + src/main/java/emissary/util/DataUtil.java | 3 ++ .../java/emissary/util/magic/MagicNumber.java | 1 + .../util/search/BackwardsTreeScanner.java | 1 + .../emissary/util/search/FastBoyerMoore.java | 1 + .../util/search/IMultiKeywordScanner.java | 1 + 17 files changed, 114 insertions(+), 4 deletions(-) diff --git a/src/main/java/emissary/admin/PlaceStarter.java b/src/main/java/emissary/admin/PlaceStarter.java index d4539cd459..b83f0fb9f2 100755 --- a/src/main/java/emissary/admin/PlaceStarter.java +++ b/src/main/java/emissary/admin/PlaceStarter.java @@ -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; @@ -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. @@ -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 constructorArgs, + @Nullable final String theClassStr) { logger.debug("Ready to createPlace {} as {}", theLocation, theClassStr); final long t1 = System.currentTimeMillis(); diff --git a/src/main/java/emissary/client/EmissaryResponse.java b/src/main/java/emissary/client/EmissaryResponse.java index 7ecf97ac7e..d3dc7dd2e5 100644 --- a/src/main/java/emissary/client/EmissaryResponse.java +++ b/src/main/java/emissary/client/EmissaryResponse.java @@ -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); diff --git a/src/main/java/emissary/config/ConfigUtil.java b/src/main/java/emissary/config/ConfigUtil.java index 127aea4deb..99639ffbb6 100755 --- a/src/main/java/emissary/config/ConfigUtil.java +++ b/src/main/java/emissary/config/ConfigUtil.java @@ -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)); } @@ -510,6 +513,7 @@ public static List 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]; diff --git a/src/main/java/emissary/core/Factory.java b/src/main/java/emissary/core/Factory.java index d553452588..866704cbd9 100755 --- a/src/main/java/emissary/core/Factory.java +++ b/src/main/java/emissary/core/Factory.java @@ -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 + ")"); @@ -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 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. diff --git a/src/main/java/emissary/core/IMobileAgent.java b/src/main/java/emissary/core/IMobileAgent.java index fa4daf9649..17eed7bdce 100755 --- a/src/main/java/emissary/core/IMobileAgent.java +++ b/src/main/java/emissary/core/IMobileAgent.java @@ -52,6 +52,7 @@ void arrive(Object payload, IServiceProviderPlace arrivalPlace, int mec, List 0) { for (String alg : algs) { diff --git a/src/main/java/emissary/output/DropOffPlace.java b/src/main/java/emissary/output/DropOffPlace.java index c92daec2fd..d6cddc76f3 100755 --- a/src/main/java/emissary/output/DropOffPlace.java +++ b/src/main/java/emissary/output/DropOffPlace.java @@ -459,13 +459,25 @@ public List 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 getFilterNamesList() { final List fnames = new ArrayList<>(); for (final IDropOffFilter f : this.outputFilters) { fnames.add(f.getFilterName()); } - return fnames.toArray(new String[0]); + return fnames; } /** diff --git a/src/main/java/emissary/output/DropOffUtil.java b/src/main/java/emissary/output/DropOffUtil.java index aa6b1694c1..57a274906a 100755 --- a/src/main/java/emissary/output/DropOffUtil.java +++ b/src/main/java/emissary/output/DropOffUtil.java @@ -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; @@ -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 getExistingIdsList(final IBaseDataObject d) { final List values = new ArrayList<>(); for (final String s : this.idTokens) { if (!StringUtils.isBlank(d.getStringParameter(s))) { @@ -508,7 +522,7 @@ public String[] getExistingIds(final IBaseDataObject d) { } } } - return values.toArray(new String[0]); + return values; } public String getRootPath() { @@ -941,8 +955,23 @@ public static List 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 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 getFullFilepathsFromParams(IBaseDataObject d, List filenameFields) { List filenames = new ArrayList<>(); diff --git a/src/main/java/emissary/pickup/WorkSpace.java b/src/main/java/emissary/pickup/WorkSpace.java index 596edec195..80d0aec30c 100755 --- a/src/main/java/emissary/pickup/WorkSpace.java +++ b/src/main/java/emissary/pickup/WorkSpace.java @@ -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 showPendingItemsList() { final List list = new ArrayList<>(); synchronized (this.QLOCK) { for (final Map.Entry entry : this.pending.entrySet()) { list.add(entry.getValue().toString()); } } - return list.toArray(new String[0]); + return list; } /** diff --git a/src/main/java/emissary/server/mvc/adapters/RequestUtil.java b/src/main/java/emissary/server/mvc/adapters/RequestUtil.java index 1303dad3e4..8f513fe1c6 100755 --- a/src/main/java/emissary/server/mvc/adapters/RequestUtil.java +++ b/src/main/java/emissary/server/mvc/adapters/RequestUtil.java @@ -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; diff --git a/src/main/java/emissary/util/ConstructorLookupCache.java b/src/main/java/emissary/util/ConstructorLookupCache.java index 7706831ed2..c4eebc71fe 100644 --- a/src/main/java/emissary/util/ConstructorLookupCache.java +++ b/src/main/java/emissary/util/ConstructorLookupCache.java @@ -19,6 +19,7 @@ * cache does not guarantee 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); diff --git a/src/main/java/emissary/util/DataUtil.java b/src/main/java/emissary/util/DataUtil.java index ea2f30168f..75420c6863 100644 --- a/src/main/java/emissary/util/DataUtil.java +++ b/src/main/java/emissary/util/DataUtil.java @@ -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); diff --git a/src/main/java/emissary/util/magic/MagicNumber.java b/src/main/java/emissary/util/magic/MagicNumber.java index 760d5eddcd..1169f7a562 100644 --- a/src/main/java/emissary/util/magic/MagicNumber.java +++ b/src/main/java/emissary/util/magic/MagicNumber.java @@ -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<>(); diff --git a/src/main/java/emissary/util/search/BackwardsTreeScanner.java b/src/main/java/emissary/util/search/BackwardsTreeScanner.java index 410a16021e..1eb0655129 100755 --- a/src/main/java/emissary/util/search/BackwardsTreeScanner.java +++ b/src/main/java/emissary/util/search/BackwardsTreeScanner.java @@ -17,6 +17,7 @@ * @author ce * @version 1.0 */ +@SuppressWarnings("AvoidObjectArrays") public class BackwardsTreeScanner { // The internal structure of the offset-keyword id array diff --git a/src/main/java/emissary/util/search/FastBoyerMoore.java b/src/main/java/emissary/util/search/FastBoyerMoore.java index ea0c7cea11..374f083ecd 100755 --- a/src/main/java/emissary/util/search/FastBoyerMoore.java +++ b/src/main/java/emissary/util/search/FastBoyerMoore.java @@ -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; diff --git a/src/main/java/emissary/util/search/IMultiKeywordScanner.java b/src/main/java/emissary/util/search/IMultiKeywordScanner.java index 372f8a6b7c..f0ad71a67a 100755 --- a/src/main/java/emissary/util/search/IMultiKeywordScanner.java +++ b/src/main/java/emissary/util/search/IMultiKeywordScanner.java @@ -1,5 +1,6 @@ package emissary.util.search; +@SuppressWarnings("AvoidObjectArrays") public interface IMultiKeywordScanner { void loadKeywords(String[] keywords);