Merge pull request #5005 from wschaeferB/5297-CodacyErrorCleanup

5297 codacy error cleanup
This commit is contained in:
Richard Cordovano 2019-11-08 12:12:42 -05:00 committed by GitHub
commit c557b6264c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 112 additions and 82 deletions

View File

@ -1,7 +1,7 @@
/*
* Autopsy Forensic Browser
*
* Copyright 2012 Basis Technology Corp.
* Copyright 2012-2019 Basis Technology Corp.
* Contact: carrier <at> sleuthkit <dot> org
*
* Licensed under the Apache License, Version 2.0 (the "License");
@ -20,6 +20,7 @@ package org.sleuthkit.autopsy.coreutils;
import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.openide.util.NbBundle;
@ -35,43 +36,43 @@ import org.sleuthkit.autopsy.coreutils.LnkEnums.NetworkProviderType;
*/
public class JLNK {
private int header;
private byte[] linkClassIdentifier;
private List<LinkFlags> linkFlags;
private List<FileAttributesFlags> fileAttributesFlags;
private long crtime;
private long atime;
private long mtime;
private int fileSize;
private int iconIndex;
private int showCommand;
private short hotKey;
private final int header;
private final byte[] linkClassIdentifier;
private final List<LinkFlags> linkFlags;
private final List<FileAttributesFlags> fileAttributesFlags;
private final long crtime;
private final long atime;
private final long mtime;
private final int fileSize;
private final int iconIndex;
private final int showCommand;
private final short hotKey;
private List<String> linkTargetIdList;
private final List<String> linkTargetIdList;
private boolean hasUnicodeLocalBaseAndCommonSuffixOffset;
private String localBasePath;
private String commonPathSuffix;
private String localBasePathUnicode;
private String commonPathSuffixUnicode;
private final boolean hasUnicodeLocalBaseAndCommonSuffixOffset;
private final String localBasePath;
private final String commonPathSuffix;
private final String localBasePathUnicode;
private final String commonPathSuffixUnicode;
private String name;
private String relativePath;
private String workingDir;
private String arguments;
private String iconLocation;
private final String name;
private final String relativePath;
private final String workingDir;
private final String arguments;
private final String iconLocation;
private int driveSerialNumber;
private DriveType driveType;
private String volumeLabel;
private final int driveSerialNumber;
private final DriveType driveType;
private final String volumeLabel;
private List<CommonNetworkRelativeLinkFlags> commonNetworkRelativeListFlags;
private NetworkProviderType networkProviderType;
private boolean unicodeNetAndDeviceName;
private String netName;
private String netNameUnicode;
private String deviceName;
private String deviceNameUnicode;
private final List<CommonNetworkRelativeLinkFlags> commonNetworkRelativeListFlags;
private final NetworkProviderType networkProviderType;
private final boolean unicodeNetAndDeviceName;
private final String netName;
private final String netNameUnicode;
private final String deviceName;
private final String deviceNameUnicode;
public JLNK(int header, byte[] linkClassIdentifier, int linkFlags,
int fileAttributesFlags, long crtime, long atime,
@ -87,14 +88,14 @@ public class JLNK {
String netName, String netNameUnicode, String deviceName,
String deviceNameUnicode) {
this.header = header;
this.linkClassIdentifier = linkClassIdentifier;
this.linkFlags = new ArrayList<LinkFlags>();
this.linkClassIdentifier = linkClassIdentifier.clone();
this.linkFlags = new ArrayList<>();
for (LnkEnums.LinkFlags enumVal : LnkEnums.LinkFlags.values()) {
if ((linkFlags & enumVal.getFlag()) == enumVal.getFlag()) {
this.linkFlags.add(enumVal);
}
}
this.fileAttributesFlags = new ArrayList<FileAttributesFlags>();
this.fileAttributesFlags = new ArrayList<>();
for (LnkEnums.FileAttributesFlags enumVal : LnkEnums.FileAttributesFlags.values()) {
if ((fileAttributesFlags & enumVal.getFlag()) == enumVal.getFlag()) {
this.fileAttributesFlags.add(enumVal);
@ -121,7 +122,7 @@ public class JLNK {
this.driveSerialNumber = driveSerialNumber;
this.driveType = driveType;
this.volumeLabel = volumeLabel;
this.commonNetworkRelativeListFlags = new ArrayList<CommonNetworkRelativeLinkFlags>();
this.commonNetworkRelativeListFlags = new ArrayList<>();
for (LnkEnums.CommonNetworkRelativeLinkFlags enumVal : LnkEnums.CommonNetworkRelativeLinkFlags.values()) {
if ((commonNetworkRelativeListFlags & enumVal.getFlag()) == enumVal.getFlag()) {
this.commonNetworkRelativeListFlags.add(enumVal);
@ -140,7 +141,7 @@ public class JLNK {
}
public List<CommonNetworkRelativeLinkFlags> getCommonNetworkRelativeListFlags() {
return commonNetworkRelativeListFlags;
return Collections.unmodifiableList(commonNetworkRelativeListFlags);
}
public String getCommonPathSuffix() {
@ -176,7 +177,7 @@ public class JLNK {
}
public List<FileAttributesFlags> getFileAttributesFlags() {
return fileAttributesFlags;
return Collections.unmodifiableList(fileAttributesFlags);
}
public int getFileSize() {
@ -196,7 +197,7 @@ public class JLNK {
}
public List<String> getLinkTargetIdList() {
return linkTargetIdList;
return Collections.unmodifiableList(linkTargetIdList);
}
public int getIconIndex() {
@ -208,11 +209,11 @@ public class JLNK {
}
public byte[] getLinkClassIdentifier() {
return linkClassIdentifier;
return linkClassIdentifier.clone();
}
public List<LinkFlags> getLinkFlags() {
return linkFlags;
return Collections.unmodifiableList(linkFlags);
}
public String getLocalBasePath() {

View File

@ -1,7 +1,7 @@
/*
* Autopsy Forensic Browser
*
* Copyright 2012 Basis Technology Corp.
* Copyright 2012-2019 Basis Technology Corp.
* Contact: carrier <at> sleuthkit <dot> org
*
* Licensed under the Apache License, Version 2.0 (the "License");
@ -31,6 +31,10 @@ class LnkEnums {
private static final byte[] IEFRAME = new byte[]{(byte) 0x80, 0x53, 0x1c, (byte) 0x87, (byte) 0xa0,
0x42, 0x69, 0x10, (byte) 0xa2, (byte) 0xea, 0x08, 0x00, 0x2b, 0x30, 0x30, (byte) 0x9d};
private LnkEnums() {
//private constructor for utility class
}
public enum CommonCLSIDS {
CDrivesFolder(CDRIVES),
@ -38,20 +42,24 @@ class LnkEnums {
IEFrameDLL(IEFRAME),
Unknown(new byte[16]);
private byte[] flag;
private final byte[] flag;
private CommonCLSIDS(byte[] flag) {
this.flag = flag;
this.flag = flag.clone();
}
static CommonCLSIDS valueOf(byte[] type) {
for (CommonCLSIDS value : CommonCLSIDS.values()) {
if (java.util.Arrays.equals(value.flag, type)) {
if (java.util.Arrays.equals(value.getFlag(), type)) {
return value;
}
}
return Unknown;
}
byte[] getFlag() {
return flag.clone();
}
}
public enum LinkFlags {
@ -84,7 +92,7 @@ class LnkEnums {
PreferEnvironmentPath(0x02000000),
KeepLocalIDListForUNCTarget(0x04000000);
private int flag;
private final int flag;
private LinkFlags(int flag) {
this.flag = flag;
@ -105,7 +113,7 @@ class LnkEnums {
DRIVE_CDROM(0x00000005),
DRIVE_RAMDISK(0x00000006);
private int flag;
private final int flag;
private DriveType(int flag) {
this.flag = flag;
@ -117,7 +125,7 @@ class LnkEnums {
static DriveType valueOf(int type) {
for (DriveType value : DriveType.values()) {
if (value.flag == type) {
if (value.getFlag() == type) {
return value;
}
}
@ -143,7 +151,7 @@ class LnkEnums {
NOT_CONTENT_INDEXED(0x00002000),
ENCRYPTED(0x00004000);
private int flag;
private final int flag;
private FileAttributesFlags(int flag) {
this.flag = flag;
@ -159,7 +167,7 @@ class LnkEnums {
VolumeIDAndLocalBasePath(0x00000001),
CommonNetworkRelativeLinkAndPathSuffix(0x00000002);
private int flag;
private final int flag;
private LinkInfoFlags(int flag) {
this.flag = flag;
@ -175,7 +183,7 @@ class LnkEnums {
ValidDevice(0x00000001),
ValidNetType(0x00000002);
private int flag;
private final int flag;
private CommonNetworkRelativeLinkFlags(int flag) {
this.flag = flag;
@ -231,7 +239,7 @@ class LnkEnums {
WNNC_NET_GOOGLE(0x00430000),
WNNC_NET_UNKNOWN(0x00000000);
private int flag;
private final int flag;
private NetworkProviderType(int flag) {
this.flag = flag;
@ -239,7 +247,7 @@ class LnkEnums {
static NetworkProviderType valueOf(int type) {
for (NetworkProviderType value : NetworkProviderType.values()) {
if (value.flag == type) {
if (value.getFlag() == type) {
return value;
}
}
@ -250,4 +258,5 @@ class LnkEnums {
return flag;
}
}
}

View File

@ -1,7 +1,7 @@
/*
* Autopsy Forensic Browser
*
* Copyright 2011-2017 Basis Technology Corp.
* Copyright 2011-2019 Basis Technology Corp.
* Contact: carrier <at> sleuthkit <dot> org
*
* Licensed under the Apache License, Version 2.0 (the "License");
@ -25,6 +25,7 @@ import javax.annotation.concurrent.GuardedBy;
import javax.annotation.concurrent.ThreadSafe;
import javax.swing.JDialog;
import javax.swing.SwingUtilities;
import org.apache.commons.lang3.SerializationUtils;
import org.openide.DialogDescriptor;
import org.openide.DialogDisplayer;
import org.openide.util.HelpCtx;
@ -65,7 +66,7 @@ public final class ModalDialogProgressIndicator implements ProgressIndicator {
this.title = title;
progressPanel = new ProgressPanel();
progressPanel.setIndeterminate(true);
this.buttonLabels = buttonLabels;
this.buttonLabels = SerializationUtils.clone(buttonLabels);
this.focusedButtonLabel = focusedButtonLabel;
this.buttonListener = buttonListener;
}

View File

@ -1,7 +1,7 @@
/*
* Autopsy Forensic Browser
*
* Copyright 2018-2018 Basis Technology Corp.
* Copyright 2018-2019 Basis Technology Corp.
* Contact: carrier <at> sleuthkit <dot> org
*
* Licensed under the Apache License, Version 2.0 (the "License");
@ -44,7 +44,7 @@ final class SqliteTextExtractor implements TextExtractor {
private static final Logger logger = Logger.getLogger(SqliteTextExtractor.class.getName());
private final AbstractFile file;
public SqliteTextExtractor(AbstractFile file) {
SqliteTextExtractor(AbstractFile file) {
this.file = file;
}
/**
@ -101,7 +101,7 @@ final class SqliteTextExtractor implements TextExtractor {
*
* @param file Sqlite file
*/
public SQLiteStreamReader(AbstractFile file) {
SQLiteStreamReader(AbstractFile file) {
this.file = file;
reader = new SQLiteTableReader.Builder(file)
.forAllColumnNames(getColumnNameStrategy())
@ -140,7 +140,7 @@ final class SqliteTextExtractor implements TextExtractor {
}
fillBuffer(objectStr);
columnIndex = columnIndex % totalColumns;
columnIndex %= totalColumns;
}
};
}
@ -171,7 +171,7 @@ final class SqliteTextExtractor implements TextExtractor {
fillBuffer(columnName + ((columnIndex == totalColumns) ? "\n" : " "));
//Reset the columnCount to 0 for next table read
columnIndex = columnIndex % totalColumns;
columnIndex %= totalColumns;
}
};
}
@ -204,7 +204,7 @@ final class SqliteTextExtractor implements TextExtractor {
*/
@Override
public int read(char[] cbuf, int off, int len) throws IOException {
buf = cbuf;
buf = cbuf; //needs to be the same memory address and not a copy of the contents since we are filling it in
bufIndex = off;
@ -277,12 +277,12 @@ final class SqliteTextExtractor implements TextExtractor {
private final String entity;
private Integer pointer;
public ExcessBytes(String entity, Integer pointer) {
ExcessBytes(String entity, Integer pointer) {
this.entity = entity;
this.pointer = pointer;
}
public boolean isFinished() {
boolean isFinished() {
return entity.length() == pointer;
}
@ -296,7 +296,7 @@ final class SqliteTextExtractor implements TextExtractor {
*
* @return number of characters read into the buffer
*/
public int read(char[] buf, int off, int len) {
int read(char[] buf, int off, int len) {
for (int i = off; i < len; i++) {
if (isFinished()) {
return i - off;

View File

@ -1,7 +1,7 @@
/*
* Autopsy Forensic Browser
*
* Copyright 2015-2018 Basis Technology Corp.
* Copyright 2015-2019 Basis Technology Corp.
* Contact: carrier <at> sleuthkit <dot> org
*
* Licensed under the Apache License, Version 2.0 (the "License");
@ -178,6 +178,20 @@ final class FileExportRuleSet implements Serializable, Comparable<FileExportRule
this.artifactConditions = new ArrayList<>();
}
/**
* Sort the file size conditions of this rule.
*/
void sortFileSizeConditions() {
this.fileSizeConditions.sort(null);
}
/**
* Sort the artifact conditions of this rule.
*/
void sortArtifactConditions() {
this.artifactConditions.sort(null);
}
/**
* Gets the name of the rule.
*
@ -336,13 +350,13 @@ final class FileExportRuleSet implements Serializable, Comparable<FileExportRule
if (!Objects.equals(this.fileTypeCondition, that.getFileMIMETypeCondition())) {
return false;
}
this.fileSizeConditions.sort(null);
that.fileSizeConditions.sort(null);
this.sortFileSizeConditions();
that.sortFileSizeConditions();
if (!this.fileSizeConditions.equals(that.getFileSizeConditions())) {
return false;
}
this.artifactConditions.sort(null);
that.artifactConditions.sort(null);
this.sortArtifactConditions();
that.sortArtifactConditions();
return this.artifactConditions.equals(that.getArtifactConditions());
}
@ -376,8 +390,8 @@ final class FileExportRuleSet implements Serializable, Comparable<FileExportRule
List<Long> evaluate(long dataSourceId) throws ExportRulesException {
try {
SleuthkitCase db = Case.getCurrentCaseThrows().getSleuthkitCase();
try (SleuthkitCase.CaseDbQuery queryResult = db.executeQuery(getQuery(dataSourceId))) {
ResultSet resultSet = queryResult.getResultSet();
try (SleuthkitCase.CaseDbQuery queryResult = db.executeQuery(getQuery(dataSourceId));
ResultSet resultSet = queryResult.getResultSet();) {
List<Long> fileIds = new ArrayList<>();
while (resultSet.next()) {
fileIds.add(resultSet.getLong("obj_id"));
@ -889,7 +903,7 @@ final class FileExportRuleSet implements Serializable, Comparable<FileExportRule
* @return The value, may be null.
*/
byte[] getByteValue() {
return this.byteValue;
return this.byteValue.clone();
}
/**
@ -908,7 +922,7 @@ final class FileExportRuleSet implements Serializable, Comparable<FileExportRule
* @return The value, may be null.
*/
String getStringRepresentationOfValue() {
String valueText = "";
String valueText;
switch (this.attributeValueType) {
case BYTE:
valueText = new String(Hex.encodeHex(getByteValue()));
@ -1069,20 +1083,20 @@ final class FileExportRuleSet implements Serializable, Comparable<FileExportRule
}
SleuthkitCase caseDb = currentCase.getSleuthkitCase();
BlackboardArtifact.Type artifactType;
BlackboardAttribute.Type attributeType;
try {
artifactType = caseDb.getArtifactType(artifactTypeName);
} catch (TskCoreException ex) {
throw new ExportRulesException(String.format("The specified %s artifact type does not exist in case database for %s", artifactTypeName, currentCase.getCaseDirectory()), ex);
}
BlackboardAttribute.Type attributeType;
try {
attributeType = caseDb.getAttributeType(attributeTypeName);
} catch (TskCoreException ex) {
throw new ExportRulesException(String.format("The specified %s attribute type does not exist in case database for %s", attributeTypeName, currentCase.getCaseDirectory()), ex);
}
String clause = String.format("files.obj_id = arts%d.obj_id AND arts%d.artifact_type_id = %d AND attrs%d.artifact_id = arts%d.artifact_id AND attrs%d.attribute_type_id = %d AND ",
index, index, artifactType.getTypeID(), index, index, index, attributeType.getTypeID());
index, index, artifactType.getTypeID(), index, index, index, attributeType.getTypeID());
switch (this.attributeValueType) {
case INTEGER:
clause += String.format("attrs%d.value_int32 %s %d", index, this.op.getSymbol(), this.intValue);
@ -1100,7 +1114,9 @@ final class FileExportRuleSet implements Serializable, Comparable<FileExportRule
clause += String.format("attrs%d.value_byte %s decode('%s', 'hex')", index, this.op.getSymbol(), new String(Hex.encodeHex(getByteValue())));
break;
case DATETIME:
clause += String.format("attrs%d.value_int64 %s '%s'", index, this.op.getSymbol(), this.dateTimeValue.getMillis()/1000);
clause += String.format("attrs%d.value_int64 %s '%s'", index, this.op.getSymbol(), this.dateTimeValue.getMillis() / 1000);
break;
default:
break;
}
return clause;

View File

@ -42,6 +42,7 @@ import org.sleuthkit.autopsy.recentactivity.BinaryCookieReader.Cookie;
*/
final class BinaryCookieReader implements Iterable<Cookie> {
private static final Logger LOG = Logger.getLogger(BinaryCookieReader.class.getName());
private static final int MAGIC_SIZE = 4;
private static final int SIZEOF_INT_BYTES = 4;
private static final int PAGE_HEADER_VALUE = 256;
@ -53,8 +54,6 @@ final class BinaryCookieReader implements Iterable<Cookie> {
private final int[] pageSizeArray;
private final File cookieFile;
private static final Logger LOG = Logger.getLogger(BinaryCookieReader.class.getName());
/**
* The binary cookie reader encapsulates all the knowledge of how to read
* the mac .binarycookie files into one class.
@ -62,7 +61,7 @@ final class BinaryCookieReader implements Iterable<Cookie> {
*/
private BinaryCookieReader(File cookieFile, int[] pageSizeArray) {
this.cookieFile = cookieFile;
this.pageSizeArray = pageSizeArray;
this.pageSizeArray = pageSizeArray.clone();
}
/**
@ -71,7 +70,9 @@ final class BinaryCookieReader implements Iterable<Cookie> {
* open.
*
* @param cookieFile binarycookie file
*
* @return An instance of the reader
*
* @throws FileNotFoundException
* @throws IOException
*/
@ -229,6 +230,7 @@ final class BinaryCookieReader implements Iterable<Cookie> {
* correct format by checking for the header value of 0x0100.
*
* @param page byte array representing a cookie page
*
* @throws IOException
*/
CookiePage(byte[] page) throws IOException {
@ -414,7 +416,8 @@ final class BinaryCookieReader implements Iterable<Cookie> {
* offset ending at the first null terminator found.
*
* @param byteArray Array of bytes
* @param offset starting offset in the array
* @param offset starting offset in the array
*
* @return String with bytes converted to ascii
*/
private String decodeString(byte[] byteArray, int offset) {