Skip to content

Commit

Permalink
errorprone :: ConstantField (#872)
Browse files Browse the repository at this point in the history
  • Loading branch information
jpdahlke authored Aug 14, 2024
1 parent 091d982 commit 6c3ae4b
Show file tree
Hide file tree
Showing 11 changed files with 53 additions and 52 deletions.
8 changes: 4 additions & 4 deletions src/main/java/emissary/command/ServiceCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ public abstract class ServiceCommand extends HttpCommand {

static final Logger LOG = LoggerFactory.getLogger(ServiceCommand.class);

public static String COMMAND_NAME = "ServiceCommand";
public static String SERVICE_HEALTH_ENDPOINT = "/api/" + HEALTH;
public static String SERVICE_SHUTDOWN_ENDPOINT = "/api/" + SHUTDOWN;
public static String SERVICE_KILL_ENDPOINT = SERVICE_SHUTDOWN_ENDPOINT + "/force";
public static final String COMMAND_NAME = "ServiceCommand";
public static final String SERVICE_HEALTH_ENDPOINT = "/api/" + HEALTH;
public static final String SERVICE_SHUTDOWN_ENDPOINT = "/api/" + SHUTDOWN;
public static final String SERVICE_KILL_ENDPOINT = SERVICE_SHUTDOWN_ENDPOINT + "/force";

@Option(names = {"--csrf"}, description = "disable csrf protection\nDefault: ${DEFAULT-VALUE}", arity = "1")
private boolean csrf = true;
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/emissary/id/SizeIdPlace.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* Id place that sets the current form based on size of the data
*/
public class SizeIdPlace extends IdPlace {
protected int[] SIZES = {0, // ZERO
protected static final int[] SIZES = {0, // ZERO
200, // TINY
3000, // SMALL
40000, // MEDIUM
Expand All @@ -20,14 +20,14 @@ public class SizeIdPlace extends IdPlace {
900000000 // ASTRONOMICAL
};

protected String[] LABELS = {"SIZE_ZERO", "SIZE_TINY", "SIZE_SMALL", "SIZE_MEDIUM", "SIZE_LARGE", "SIZE_HUGE", "SIZE_ENORMOUS",
protected static final String[] LABELS = {"SIZE_ZERO", "SIZE_TINY", "SIZE_SMALL", "SIZE_MEDIUM", "SIZE_LARGE", "SIZE_HUGE", "SIZE_ENORMOUS",
"SIZE_ASTRONOMICAL"};

/** True iff the Filetype should be set */
protected boolean SETFT = true;
protected boolean setFileType = true;

/** True iff the current form should be set */
protected boolean SETCF = true;
protected boolean setCurrentForm = true;

/**
* Create the place
Expand Down Expand Up @@ -67,10 +67,10 @@ protected void configurePlace() {}
@Override
public List<IBaseDataObject> processHeavyDuty(IBaseDataObject payload) {
String szType = fileTypeBySize(payload.dataLength());
if (SETFT) {
if (setFileType) {
payload.setFileType(szType);
}
if (SETCF) {
if (setCurrentForm) {
payload.setCurrentForm(szType);
}

Expand Down
9 changes: 5 additions & 4 deletions src/main/java/emissary/kff/KffChain.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ public class KffChain {
protected List<KffFilter> list = new ArrayList<>();

// Smaller than this and we don't report a hit
protected int KFF_MIN_DATA_SIZE = 0;
protected static final int DEFAULT_KFF_MIN_DATA_SIZE = 0;
protected int kffMinDataSize = DEFAULT_KFF_MIN_DATA_SIZE;

// The algorithms to compute
protected List<String> algorithms = new ArrayList<>();
Expand Down Expand Up @@ -58,7 +59,7 @@ public void setMinDataSize(int i) {
if (i < 0) {
i = 0;
}
KFF_MIN_DATA_SIZE = i;
kffMinDataSize = i;
}

/**
Expand Down Expand Up @@ -122,7 +123,7 @@ public List<String> getAlgorithms() {
public KffResult check(final String itemName, final byte[] content) throws Exception {
final ChecksumResults sums = computeSums(content);
KffResult answer = null;
if (content.length < KFF_MIN_DATA_SIZE || list.isEmpty()) {
if (content.length < kffMinDataSize || list.isEmpty()) {
answer = new KffResult(sums);
answer.setItemName(itemName);
} else {
Expand Down Expand Up @@ -156,7 +157,7 @@ public KffResult check(final String itemName, final SeekableByteChannelFactory s
try (final SeekableByteChannel sbc = sbcf.create()) {
sbcSize = sbc.size();
}
if (sbcSize < KFF_MIN_DATA_SIZE || list.isEmpty()) {
if (sbcSize < kffMinDataSize || list.isEmpty()) {
answer = new KffResult(sums);
answer.setItemName(itemName);
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/emissary/kff/Ssdeep.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public final class Ssdeep {
private static final int SPAMSUM_LENGTH = 64;
private static final int MIN_BLOCKSIZE = 3;

public final int FUZZY_MAX_RESULT = (SPAMSUM_LENGTH + (SPAMSUM_LENGTH / 2 + 20));
public static final int FUZZY_MAX_RESULT = (SPAMSUM_LENGTH + (SPAMSUM_LENGTH / 2 + 20));

/** The window size for the rolling hash. */
private static final int ROLLING_WINDOW_SIZE = 7;
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/emissary/parser/DataIdentifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ public class DataIdentifier {
public static final String UNKNOWN_TYPE = "simple";

// Size of string to test
protected int DATA_ID_STR_SZ = 100;
protected static final int DATA_ID_STR_SZ = 100;

// Things we know how to identify
protected Map<String, String> TYPES = new HashMap<>();
protected Map<String, String> typesMap = new HashMap<>();

/**
* Create the id engine
Expand All @@ -49,8 +49,8 @@ protected void configure(@Nullable Configurator config) {
if (config == null) {
config = ConfigUtil.getConfigInfo(this.getClass());
}
TYPES = config.findStringMatchMap("TYPE_", Configurator.PRESERVE_CASE);
logger.debug("Configured with " + TYPES.size() + " identifiction types");
typesMap = config.findStringMatchMap("TYPE_", Configurator.PRESERVE_CASE);
logger.debug("Configured with " + typesMap.size() + " identifiction types");
} catch (IOException iox) {
logger.debug("No configuration info found");
}
Expand Down Expand Up @@ -85,7 +85,7 @@ protected String getTestString(byte[] data) {
* @param data array of data to identify
*/
public String identify(byte[] data) {
for (Map.Entry<String, String> entry : TYPES.entrySet()) {
for (Map.Entry<String, String> entry : typesMap.entrySet()) {
byte[] pattern = entry.getValue().getBytes();
if (data.length < pattern.length) {
continue;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/emissary/parser/SessionParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
public abstract class SessionParser {
public static final int MAX_ARRAY_SIZE = Integer.MAX_VALUE - 10;
public static final long MAX_ARRAY_SIZE_LONG = MAX_ARRAY_SIZE;
public static String ORIG_DOC_SIZE_KEY = "OrigDocumentSize";
public static final String ORIG_DOC_SIZE_KEY = "OrigDocumentSize";

protected boolean fullyParsed = false;

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/emissary/place/MultiFileServerPlace.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/
public abstract class MultiFileServerPlace extends PickUpPlace implements IMultiFileServerPlace {
protected TypeEngine typeEngine;
protected Set<?> NON_PROPAGATING_METADATA_VALS;
protected Set<?> nonPropagatingMetadataValues;

public MultiFileServerPlace() throws IOException {
super();
Expand Down Expand Up @@ -58,7 +58,7 @@ public MultiFileServerPlace(InputStream configStream, String thePlaceLocation) t
*/
private void configureAbstractPlace() {
typeEngine = new TypeEngine(configG);
NON_PROPAGATING_METADATA_VALS = configG.findEntriesAsSet("NON_PROPAGATING_METADATA");
nonPropagatingMetadataValues = configG.findEntriesAsSet("NON_PROPAGATING_METADATA");
}

/**
Expand Down
19 changes: 9 additions & 10 deletions src/main/java/emissary/place/MultiFileUnixCommandPlace.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ public class MultiFileUnixCommandPlace extends MultiFileServerPlace implements I
protected List<String> binFileExt = null;
@Nullable
protected List<String> outDirs = null;
protected String SINGLE_CHILD_FILETYPE = Form.UNKNOWN;
protected boolean KEEP_PARENT_HASHES_FOR_SINGLE_CHILD = false;
protected boolean KEEP_PARENT_FILETYPE_FOR_SINGLE_CHILD = false;
protected String singleChildFiletype = Form.UNKNOWN;
protected boolean keepParentHashesForSingleChild = false;
protected boolean keepParentFiletypeForSingleChild = false;
protected static final String DEFAULT_NEW_PARENT_FORM = "SAFE_HTML";
protected static final String DEFAULT_NEW_CHILD_FORM = Form.UNKNOWN;
protected static final String DEFAULT_NEW_ERROR_FORM = Form.ERROR;
Expand Down Expand Up @@ -137,10 +137,9 @@ public void configurePlace() {
newParentForm = null;
}
newChildForms = configG.findEntries("NEW_CHILD_FORM", DEFAULT_NEW_CHILD_FORM);
SINGLE_CHILD_FILETYPE = configG.findStringEntry("SINGLE_CHILD_FILETYPE", SINGLE_CHILD_FILETYPE);
KEEP_PARENT_HASHES_FOR_SINGLE_CHILD = configG.findBooleanEntry("KEEP_PARENT_HASHES_FOR_SINGLE_CHILD", KEEP_PARENT_HASHES_FOR_SINGLE_CHILD);
KEEP_PARENT_FILETYPE_FOR_SINGLE_CHILD =
configG.findBooleanEntry("KEEP_PARENT_FILETYPE_FOR_SINGLE_CHILD", KEEP_PARENT_FILETYPE_FOR_SINGLE_CHILD);
singleChildFiletype = configG.findStringEntry("SINGLE_CHILD_FILETYPE", Form.UNKNOWN);
keepParentHashesForSingleChild = configG.findBooleanEntry("KEEP_PARENT_HASHES_FOR_SINGLE_CHILD", false);
keepParentFiletypeForSingleChild = configG.findBooleanEntry("KEEP_PARENT_FILETYPE_FOR_SINGLE_CHILD", false);

setTitleToFile = configG.findBooleanEntry("SET_TITLE_TO_FILENAME", true);
placeDisplayName = configG.findStringEntry("SERVICE_DISPLAY_NAME", placeName);
Expand Down Expand Up @@ -500,7 +499,7 @@ protected int processSingleChild(IBaseDataObject d, byte[] theData, File f) {
for (String tmpForm : tmpForms) {
d.pushCurrentForm(tmpForm);
}
d.setFileType(SINGLE_CHILD_FILETYPE);
d.setFileType(singleChildFiletype);
return 0;
}

Expand Down Expand Up @@ -550,12 +549,12 @@ public List<IBaseDataObject> processHeavyDuty(IBaseDataObject tData) throws Reso
if (executrix.getOutput().equals("FILE") && entries.size() == 1 && contentFile == null && !singleOutputAsChild) {
IBaseDataObject d = entries.get(0);
tData.setData(d.data());
if (KEEP_PARENT_HASHES_FOR_SINGLE_CHILD) {
if (keepParentHashesForSingleChild) {
KffDataObjectHandler.removeHash(d);
}
tData.putUniqueParameters(d.getParameters());
tData.setCurrentForm(d.currentForm());
if (!KEEP_PARENT_FILETYPE_FOR_SINGLE_CHILD) {
if (!keepParentFiletypeForSingleChild) {
tData.setFileType(d.getFileType());
}
return Collections.emptyList(); // so we just continue with current
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/emissary/util/search/Hit.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
* Reportable result from MultiKeywordScanner
*/
public class Hit {
public static int OFFSET = 0;
public static int ID = 1;
public static final int OFFSET = 0;
public static final int ID = 1;

protected int[] hit = new int[2];

Expand Down
29 changes: 15 additions & 14 deletions src/test/java/emissary/config/ConfigUtilTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ class ConfigUtilTest extends UnitTest {

private static String configDir;
@Nullable
private Path CDIR;
private Path configPath;

@Override
@BeforeEach
public void setUp() throws Exception {
configDir = System.getProperty(ConfigUtil.CONFIG_DIR_PROPERTY, ".");
testFilesAndDirectories = new ArrayList<>();
CDIR = Paths.get(configDir);
configPath = Paths.get(configDir);

appender = new ListAppender<>();
appender.start();
Expand All @@ -70,7 +70,7 @@ public void cleanupFlavorSettings() throws Exception {
}
}
}
CDIR = null;
configPath = null;
System.clearProperty(ConfigUtil.CONFIG_FLAVOR_PROPERTY);
ConfigUtil.initialize();
}
Expand Down Expand Up @@ -271,7 +271,7 @@ void testMissingMultipleConfigDirs() throws IOException, EmissaryException {
final Path configDir1 = createTmpSubDir("config1A");
final String cfgName1 = "emissary.grapes.Monkey.cfg";
createFileAndPopulate(configDir1, cfgName1, "BOO = \"HOO\"\n");
final Path cfgName2 = Paths.get(CDIR.toString(), "configgone", "emissary.grapes.Panda.cfg");
final Path cfgName2 = Paths.get(configPath.toString(), "configgone", "emissary.grapes.Panda.cfg");
final String origConfigDirProp = System.getProperty(CONFIG_DIR_PROPERTY);
System.setProperty(CONFIG_DIR_PROPERTY, configDir1 + "," + cfgName2.getParent());

Expand Down Expand Up @@ -394,14 +394,14 @@ void testClassNameInventoryOneFile() throws IOException, EmissaryException {
@Test
void testClassNameInventoryMultipleFiles() throws IOException, EmissaryException {
final String contents1 = "DevNullPlace = \"emissary.place.sample.DevNullPlace\"\n";
createFileAndPopulate(CDIR, "emissary.admin.ClassNameInventory-core.cfg", contents1);
createFileAndPopulate(configPath, "emissary.admin.ClassNameInventory-core.cfg", contents1);

final String one = "Dev2NullPlace = \"emissary.place.donotpickme.DevNullPlace\"\n";
final String two = "DirectoryPlace = \"emissary.directory.DirectoryPlace\"";
createFileAndPopulate(CDIR, "emissary.admin.ClassNameInventory-modeone.cfg", one + two);
createFileAndPopulate(configPath, "emissary.admin.ClassNameInventory-modeone.cfg", one + two);

final String three = "Dev3NullPlace = \"emissary.place.iamtheone.DevNullPlace\"\n";
createFileAndPopulate(CDIR, "emissary.admin.ClassNameInventory-modetwo.cfg", three);
createFileAndPopulate(configPath, "emissary.admin.ClassNameInventory-modetwo.cfg", three);

ConfigUtil.initialize();

Expand Down Expand Up @@ -537,7 +537,7 @@ void testMultipleClassNameInventoryMultipleDirs() throws IOException, EmissaryEx
@Test
void testClassNameInventoryWarnsOnFlavor() throws IOException, EmissaryException {
final String contents2 = "DevNullPlace = \"emissary.place.second.DevNullPlace\"\n";
createFileAndPopulate(CDIR, "emissary.admin.ClassNameInventory-NORM.cfg", contents2);
createFileAndPopulate(configPath, "emissary.admin.ClassNameInventory-NORM.cfg", contents2);
System.setProperty(ConfigUtil.CONFIG_FLAVOR_PROPERTY, "NORM");

ConfigUtil.initialize();
Expand All @@ -555,32 +555,33 @@ void testClassNameInventoryWarnsOnFlavor() throws IOException, EmissaryException

@Test
void testGetFlavorFromFile() {
final String flavor = ConfigUtil.getFlavorsFromCfgFile(Paths.get(CDIR.toString() + "emissary.admin.ClassNameInventory-flavor1.cfg").toFile());
final String flavor =
ConfigUtil.getFlavorsFromCfgFile(Paths.get(configPath.toString() + "emissary.admin.ClassNameInventory-flavor1.cfg").toFile());
assertEquals("flavor1", flavor, "Flavors didn't match");
}

@Test
void testGetMultipleFlavorFromFile() {
final String flavor = ConfigUtil.getFlavorsFromCfgFile(Paths.get(CDIR.toString(), "emissary.junk.TrunkPlace-f1,f2,f3.cfg").toFile());
final String flavor = ConfigUtil.getFlavorsFromCfgFile(Paths.get(configPath.toString(), "emissary.junk.TrunkPlace-f1,f2,f3.cfg").toFile());
assertEquals("f1,f2,f3", flavor, "Flavors didn't match");
}

@Test
void testGetFlavorsNotACfgFile() {
final String flavor = ConfigUtil.getFlavorsFromCfgFile(Paths.get(CDIR.toString(), "emissary.util.JunkPlace-f1.config").toFile());
final String flavor = ConfigUtil.getFlavorsFromCfgFile(Paths.get(configPath.toString(), "emissary.util.JunkPlace-f1.config").toFile());
assertEquals("", flavor, "Should have been empty, not a cfg file");
}

@Test
void testGetNoFlavor() {
final String flavor = ConfigUtil.getFlavorsFromCfgFile(Paths.get(CDIR.toString(), "emissary.util.PepperPlace.config").toFile());
final String flavor = ConfigUtil.getFlavorsFromCfgFile(Paths.get(configPath.toString(), "emissary.util.PepperPlace.config").toFile());
assertEquals("", flavor, "Should have been empty, no flavor");
}

@Test
void testGetFlavorMultipleHyphens() {
final String flavor =
ConfigUtil.getFlavorsFromCfgFile(Paths.get(CDIR.toString(), "emissary.util.DrPibbPlace-flavor1-flavor2-flavor3.cfg").toFile());
ConfigUtil.getFlavorsFromCfgFile(Paths.get(configPath.toString(), "emissary.util.DrPibbPlace-flavor1-flavor2-flavor3.cfg").toFile());
assertEquals("flavor3", flavor, "Should have been the last flavor");

}
Expand Down Expand Up @@ -643,7 +644,7 @@ void testMissingImportFileInConfig(@TempDir final Path dir) throws IOException {
}

private Path createTmpSubDir(final String name) throws IOException {
final Path dir = Paths.get(CDIR.toString(), name);
final Path dir = Paths.get(configPath.toString(), name);
Files.createDirectory(dir);
testFilesAndDirectories.add(dir);
return dir;
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/emissary/place/RehashingPlaceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ void testRehash() throws Exception {
private static final class RehashPlaceTest extends ServiceProviderPlace implements RehashingPlace {

@Nullable
private byte[] USE_DATA = null;
private byte[] useData = null;

public RehashPlaceTest(InputStream config) throws IOException {
super(config);
Expand All @@ -71,15 +71,15 @@ public RehashPlaceTest(InputStream config) throws IOException {
@Override
public void process(IBaseDataObject d) {
assertNotNull(d);
d.setData(USE_DATA);
d.setData(useData);
}

public KffDataObjectHandler getKffHandler() {
return kff;
}

public void setUseData(byte[] data) {
USE_DATA = data;
useData = data;
}

}
Expand Down

0 comments on commit 6c3ae4b

Please sign in to comment.