From ad36e1d7bd84145940dcd1fc3a8df81a0f7c02c0 Mon Sep 17 00:00:00 2001 From: jpdahlke Date: Thu, 1 Aug 2024 09:45:57 -0400 Subject: [PATCH] errorprone :: ConstantField - core classes (#863) --- src/main/java/emissary/command/Banner.java | 2 +- .../java/emissary/command/EnvCommand.java | 2 +- .../java/emissary/core/BaseDataObject.java | 11 ++++------ .../java/emissary/core/DataObjectFactory.java | 16 +++++++------- src/main/java/emissary/core/MobileAgent.java | 22 ++++++++++--------- .../java/emissary/parser/ParserFactory.java | 19 ++++++++-------- .../emissary/pool/MobileAgentFactory.java | 16 +++++++------- src/main/java/emissary/roll/RollManager.java | 22 +++++++++---------- .../server/mvc/TransferDirectoryAction.java | 2 +- .../emissary/core/ExtendedDataObject.java | 2 +- 10 files changed, 57 insertions(+), 57 deletions(-) diff --git a/src/main/java/emissary/command/Banner.java b/src/main/java/emissary/command/Banner.java index e048b752dd..6f9469aba0 100644 --- a/src/main/java/emissary/command/Banner.java +++ b/src/main/java/emissary/command/Banner.java @@ -7,7 +7,7 @@ public class Banner { - static String DEFAULT_TEXT = " ________ ________ _____ _____ ___ ________ __\n" + static final String DEFAULT_TEXT = " ________ ________ _____ _____ ___ ________ __\n" + "| ___| \\/ |_ _/ ___/ ___|/ _ \\ | ___ \\ \\ / /\n" + "| |__ | . . | | | \\ `--.\\ `--./ /_\\ \\| |_/ /\\ V / \n" + "| __|| |\\/| | | | `--. \\`--. \\ _ || / \\ / \n" + "| |___| | | |_| |_/\\__/ /\\__/ / | | || |\\ \\ | | \n" + "\\____/\\_| |_/\\___/\\____/\\____/\\_| |_/\\_| \\_| \\_/ \n"; diff --git a/src/main/java/emissary/command/EnvCommand.java b/src/main/java/emissary/command/EnvCommand.java index fb3e3e70b3..1c3ba7df96 100644 --- a/src/main/java/emissary/command/EnvCommand.java +++ b/src/main/java/emissary/command/EnvCommand.java @@ -18,7 +18,7 @@ public class EnvCommand extends HttpCommand { static final Logger LOG = LoggerFactory.getLogger(EnvCommand.class); - public static int DEFAULT_PORT = 8001; + public static final int DEFAULT_PORT = 8001; @Option(names = {"--bashable"}, description = "format output for sourcing by bash\nDefault: ${DEFAULT-VALUE}") private boolean bashable = false; diff --git a/src/main/java/emissary/core/BaseDataObject.java b/src/main/java/emissary/core/BaseDataObject.java index c6082d030d..8eaf5256fa 100755 --- a/src/main/java/emissary/core/BaseDataObject.java +++ b/src/main/java/emissary/core/BaseDataObject.java @@ -148,10 +148,7 @@ public class BaseDataObject implements Serializable, Cloneable, Remote, IBaseDat protected StringBuilder brokenDocument = null; // Filetypes that we think are equivalent to no file type at all - protected String[] FILETYPE_EMPTY = {Form.UNKNOWN}; - - // Filetypes with this suffix are equivalent to no file type at all - protected String FILETYPE_ENDSWITH = "-UNWRAPPED"; + protected String[] emptyFileTypes = {Form.UNKNOWN}; /** * The integer priority of the data object. A lower number is higher priority. @@ -1162,12 +1159,12 @@ public boolean setFileTypeIfEmpty(final String v, final String[] empties) { @Override public boolean setFileTypeIfEmpty(final String v) { - return setFileTypeIfEmpty(v, this.FILETYPE_EMPTY); + return setFileTypeIfEmpty(v, this.emptyFileTypes); } @Override public boolean isFileTypeEmpty() { - return isFileTypeEmpty(this.FILETYPE_EMPTY); + return isFileTypeEmpty(this.emptyFileTypes); } /** @@ -1182,7 +1179,7 @@ protected boolean isFileTypeEmpty(@Nullable final String[] empties) { return true; } - if (s.endsWith(FILETYPE_ENDSWITH)) { + if (s.endsWith(Form.SUFFIXES_UNWRAPPED)) { return true; } diff --git a/src/main/java/emissary/core/DataObjectFactory.java b/src/main/java/emissary/core/DataObjectFactory.java index 366cbb2124..a1f07751f6 100755 --- a/src/main/java/emissary/core/DataObjectFactory.java +++ b/src/main/java/emissary/core/DataObjectFactory.java @@ -16,7 +16,7 @@ public class DataObjectFactory { public static final String DEFAULT_CLASS = BaseDataObject.class.getName(); - private static String CLAZZ; + private static String clazz; private static final Logger logger = LoggerFactory.getLogger(DataObjectFactory.class); @@ -26,10 +26,10 @@ public class DataObjectFactory { static { try { final Configurator c = ConfigUtil.getConfigInfo(AgentPool.class); - CLAZZ = c.findStringEntry("payload.class", DEFAULT_CLASS); + clazz = c.findStringEntry("payload.class", DEFAULT_CLASS); } catch (IOException ioe) { logger.warn("Unable to configure DataObjectFactory", ioe); - CLAZZ = DEFAULT_CLASS; + clazz = DEFAULT_CLASS; } } @@ -44,21 +44,21 @@ private DataObjectFactory() { * Override implementation details */ public static void setImplementingClass(final String clazz) { - CLAZZ = clazz; + DataObjectFactory.clazz = clazz; } /** * Get the name of the impl we are using */ public static String getImplementingClass() { - return CLAZZ; + return clazz; } /** * Get an instance of the configured DataObject impl */ public static IBaseDataObject getInstance() { - final Object o = Factory.create(CLAZZ); + final Object o = Factory.create(clazz); return (IBaseDataObject) o; } @@ -68,7 +68,7 @@ public static IBaseDataObject getInstance() { * @param args the arguments to the BaseDataObject constructor */ public static IBaseDataObject getInstance(final Object... args) { - final Object o = Factory.create(CLAZZ, args); + final Object o = Factory.create(clazz, args); return (IBaseDataObject) o; } @@ -94,7 +94,7 @@ public static IBaseDataObject getInstance(final byte[] payload, final String fil * @return an IBDO with the payload, filename, file type, and form set */ public static IBaseDataObject getInstance(final byte[] payload, final String filename, final String form, final String fileType) { - final Object o = Factory.create(CLAZZ, payload, filename, form, fileType); + final Object o = Factory.create(clazz, payload, filename, form, fileType); return (IBaseDataObject) o; } } diff --git a/src/main/java/emissary/core/MobileAgent.java b/src/main/java/emissary/core/MobileAgent.java index 6b81242c76..d6811352d3 100755 --- a/src/main/java/emissary/core/MobileAgent.java +++ b/src/main/java/emissary/core/MobileAgent.java @@ -44,13 +44,15 @@ public abstract class MobileAgent implements IMobileAgent, MobileAgentMBean { // Name for our threads public static final String AGENT_THREAD = "MobileAgent-"; - private static int AGENT_COUNTER = 0; + private static int agentCounter = 0; // For tracking errors - protected int MAX_MOVE_ERRORS = 3; + public static final int DEFAULT_MAX_MOVE_ERRORS = 3; + protected int maxMoveErrors = DEFAULT_MAX_MOVE_ERRORS; // For stopping infinite loops - protected int MAX_ITINERARY_STEPS = 100; + public static final int DEFAULT_MAX_ITINERARY_STEPS = 100; + protected int maxItinerarySteps = DEFAULT_MAX_ITINERARY_STEPS; // Stages of processing protected static final String ERROR_FORM = Form.ERROR; @@ -91,7 +93,7 @@ public abstract class MobileAgent implements IMobileAgent, MobileAgentMBean { * Still have an uncaught exception handler but not really in a true ThreadGroup with other agents */ public MobileAgent() { - this(new AgentThreadGroup(TG_ID), AGENT_THREAD + AGENT_COUNTER++); + this(new AgentThreadGroup(TG_ID), AGENT_THREAD + agentCounter++); } /** @@ -304,7 +306,7 @@ protected void agentControl(final IServiceProviderPlace currentPlaceArg) { } controlError = true; - if (++this.moveErrorsOccurred > this.MAX_MOVE_ERRORS || this.payload.transformHistory().size() > this.MAX_ITINERARY_STEPS) { + if (++this.moveErrorsOccurred > this.maxMoveErrors || this.payload.transformHistory().size() > this.maxItinerarySteps) { logger.error("Too many move errors, giving up"); newEntry = null; break; @@ -439,7 +441,7 @@ protected DirectoryEntry getNextKey(@Nullable final IServiceProviderPlace place, } // Stop looping from occurring - if (payloadArg.transformHistory().size() > this.MAX_ITINERARY_STEPS && + if (payloadArg.transformHistory().size() > this.maxItinerarySteps && !ERROR_FORM.equals(payloadArg.currentForm())) { payloadArg.replaceCurrentForm(ERROR_FORM); payloadArg.addProcessingError("Agent stopped due to larger than max transform history size (looping?)"); @@ -875,7 +877,7 @@ public void dumpPlaceStats() { */ @Override public int getMaxMoveErrors() { - return this.MAX_MOVE_ERRORS; + return this.maxMoveErrors; } /** @@ -886,7 +888,7 @@ public int getMaxMoveErrors() { */ @Override public void setMaxMoveErrors(final int value) { - this.MAX_MOVE_ERRORS = value; + this.maxMoveErrors = value; } /** @@ -894,7 +896,7 @@ public void setMaxMoveErrors(final int value) { */ @Override public int getMaxItinerarySteps() { - return this.MAX_ITINERARY_STEPS; + return this.maxItinerarySteps; } /** @@ -904,6 +906,6 @@ public int getMaxItinerarySteps() { */ @Override public void setMaxItinerarySteps(final int value) { - this.MAX_ITINERARY_STEPS = value; + this.maxItinerarySteps = value; } } diff --git a/src/main/java/emissary/parser/ParserFactory.java b/src/main/java/emissary/parser/ParserFactory.java index 72506f16c0..177179e968 100755 --- a/src/main/java/emissary/parser/ParserFactory.java +++ b/src/main/java/emissary/parser/ParserFactory.java @@ -35,13 +35,14 @@ public class ParserFactory { // Map of dataType to FileChannel parser implementation class name // Read from config file - protected Map NIO_TYPE_MAP = new HashMap<>(); + protected Map nioTypeMap = new HashMap<>(); // For channel sizes larger than this no fallback to a byte[] // parser is attempted. protected long nioFallbackMax = 1024L * 1024L * 100L; // 100 Mb - protected String DEFAULT_NIO_PARSER = "emissary.parser.SimpleNioParser"; + protected static final String DEFAULT_NIO_PARSER = "emissary.parser.SimpleNioParser"; + protected String nioParser = DEFAULT_NIO_PARSER; // Data type identification engine @@ -89,13 +90,13 @@ public void reconfigure(@Nullable Configurator config) { nioFallbackMax = config.findSizeEntry("MAX_NIO_FALLBACK_SIZE", nioFallbackMax); - NIO_TYPE_MAP.clear(); - NIO_TYPE_MAP.putAll(m); + nioTypeMap.clear(); + nioTypeMap.putAll(m); - logger.debug("Loaded {} nio parsers with fallback size {}", NIO_TYPE_MAP.size(), nioFallbackMax); + logger.debug("Loaded {} nio parsers with fallback size {}", nioTypeMap.size(), nioFallbackMax); // change this to "DEFAULT_PARSER" - DEFAULT_NIO_PARSER = config.findStringEntry("DEFAULT_NIO_PARSER", DEFAULT_NIO_PARSER); + nioParser = config.findStringEntry("DEFAULT_NIO_PARSER", DEFAULT_NIO_PARSER); String idEngineClass = config.findStringEntry("ID_ENGINE_CLASS", null); @@ -132,10 +133,10 @@ public SessionParser makeSessionParser(SeekableByteChannel channel) { public SessionParser makeSessionParser(String type, SeekableByteChannel channel) { SessionParser sp; - if (NIO_TYPE_MAP.containsKey(type)) { - sp = makeSessionParserClass(NIO_TYPE_MAP.get(type), channel); + if (nioTypeMap.containsKey(type)) { + sp = makeSessionParserClass(nioTypeMap.get(type), channel); } else { - sp = makeSessionParserClass(DEFAULT_NIO_PARSER, channel); + sp = makeSessionParserClass(nioParser, channel); } return sp; } diff --git a/src/main/java/emissary/pool/MobileAgentFactory.java b/src/main/java/emissary/pool/MobileAgentFactory.java index b11fd17ab2..743494229e 100755 --- a/src/main/java/emissary/pool/MobileAgentFactory.java +++ b/src/main/java/emissary/pool/MobileAgentFactory.java @@ -4,6 +4,7 @@ import emissary.config.Configurator; import emissary.core.Factory; import emissary.core.IMobileAgent; +import emissary.core.MobileAgent; import emissary.core.Namespace; import org.apache.commons.pool2.PooledObject; @@ -17,20 +18,19 @@ public class MobileAgentFactory implements PooledObjectFactory { // This is the default class when nothing else is - // configured or passed on on a constructor. This value + // configured or passed on a constructor. This value // can be overridden from the AgentPool.cfg file - static String DEFAULT_CLASS_STRING = "emissary.core.MobileAgent"; + static final String DEFAULT_CLASS_STRING = "emissary.core.MobileAgent"; - public static String AGENT_NAME = "MobileAgent"; + public static final String AGENT_NAME = "MobileAgent"; // This is the class we are going to be pooling // The value can be set by constructor, by public setter // or from the value in DEFAULT_CLASS_STRING String classString = DEFAULT_CLASS_STRING; - int maxAgentMoveErrors = 3; - - int maxAgentItinerary = 100; + int maxAgentMoveErrors; + int maxAgentItinerary; private static final Logger logger = LoggerFactory.getLogger(MobileAgentFactory.class); @@ -49,8 +49,8 @@ protected void configure() { Configurator conf = ConfigUtil.getConfigInfo(AgentPool.class); classString = conf.findStringEntry("agent.class", DEFAULT_CLASS_STRING); - maxAgentMoveErrors = conf.findIntEntry("agent.move.errors", maxAgentMoveErrors); - maxAgentItinerary = conf.findIntEntry("agent.max.itinerary", maxAgentItinerary); + maxAgentMoveErrors = conf.findIntEntry("agent.move.errors", MobileAgent.DEFAULT_MAX_MOVE_ERRORS); + maxAgentItinerary = conf.findIntEntry("agent.max.itinerary", MobileAgent.DEFAULT_MAX_ITINERARY_STEPS); } catch (IOException e) { logger.debug("Cannot read AgentPool.cfg, taking default values"); } diff --git a/src/main/java/emissary/roll/RollManager.java b/src/main/java/emissary/roll/RollManager.java index 5c18e7e8ef..3c88fe9ecb 100644 --- a/src/main/java/emissary/roll/RollManager.java +++ b/src/main/java/emissary/roll/RollManager.java @@ -29,7 +29,7 @@ public class RollManager implements PropertyChangeListener { final HashSet rollers = new HashSet<>(); // SINGLETON @Nullable - private static RollManager RM; + private static RollManager rollManager; protected RollManager() { init(); @@ -111,10 +111,10 @@ public void propertyChange(PropertyChangeEvent evt) { * Synchronized on RM to prevent multiple returns on RollManager */ public static synchronized RollManager getManager() { - if (RM == null) { - RM = new RollManager(); + if (rollManager == null) { + rollManager = new RollManager(); } - return RM; + return rollManager; } /** @@ -123,16 +123,16 @@ public static synchronized RollManager getManager() { * Used to create custom RollManager based on configs. */ public static synchronized RollManager getManager(Configurator configG) { - if (RM == null) { - RM = new RollManager(configG); + if (rollManager == null) { + rollManager = new RollManager(configG); } - return RM; + return rollManager; } public static void shutdown() { - RM.exec.shutdown(); - log.info("Closing all rollers ({})", RM.rollers.size()); - for (Roller roller : RM.rollers) { + rollManager.exec.shutdown(); + log.info("Closing all rollers ({})", rollManager.rollers.size()); + for (Roller roller : rollManager.rollers) { Rollable r = roller.getRollable(); try { r.roll(); @@ -141,7 +141,7 @@ public static void shutdown() { log.warn("Error while closing Rollable: {}", r.getClass(), ex); } } - RM = null; + rollManager = null; } private static final class RMThreadFactory implements ThreadFactory { diff --git a/src/main/java/emissary/server/mvc/TransferDirectoryAction.java b/src/main/java/emissary/server/mvc/TransferDirectoryAction.java index 71c52ee06c..d9a9c3bcaa 100644 --- a/src/main/java/emissary/server/mvc/TransferDirectoryAction.java +++ b/src/main/java/emissary/server/mvc/TransferDirectoryAction.java @@ -24,7 +24,7 @@ public class TransferDirectoryAction { private static final Logger LOG = LoggerFactory.getLogger(TransferDirectoryAction.class); - public final String TARGET_DIR_PARAM = "targetDir"; + public static final String TARGET_DIR_PARAM = "targetDir"; @GET @Path("/TransferDirectory.action") diff --git a/src/test/java/emissary/core/ExtendedDataObject.java b/src/test/java/emissary/core/ExtendedDataObject.java index 6f6b22b9a1..cf6d65d1b6 100644 --- a/src/test/java/emissary/core/ExtendedDataObject.java +++ b/src/test/java/emissary/core/ExtendedDataObject.java @@ -29,7 +29,7 @@ public class ExtendedDataObject extends BaseDataObject implements Serializable, public ExtendedDataObject() { super(); this.theData = null; - FILETYPE_EMPTY = NEW_FILETYPE_EMPTY; + emptyFileTypes = NEW_FILETYPE_EMPTY; this.intVar = 37; }