diff --git a/dependency-check-core/src/main/java/org/owasp/dependencycheck/analyzer/ArchiveAnalyzer.java b/dependency-check-core/src/main/java/org/owasp/dependencycheck/analyzer/ArchiveAnalyzer.java index a8cddd031..dc662b2c6 100644 --- a/dependency-check-core/src/main/java/org/owasp/dependencycheck/analyzer/ArchiveAnalyzer.java +++ b/dependency-check-core/src/main/java/org/owasp/dependencycheck/analyzer/ArchiveAnalyzer.java @@ -110,7 +110,7 @@ public class ArchiveAnalyzer extends AbstractFileTypeAnalyzer { static { final String additionalZipExt = Settings.getString(Settings.KEYS.ADDITIONAL_ZIP_EXTENSIONS); if (additionalZipExt != null) { - final HashSet ext = new HashSet(Arrays.asList(additionalZipExt)); + final Set ext = new HashSet(Arrays.asList(additionalZipExt)); ZIPPABLES.addAll(ext); } EXTENSIONS.addAll(ZIPPABLES); diff --git a/dependency-check-core/src/main/java/org/owasp/dependencycheck/analyzer/CPEAnalyzer.java b/dependency-check-core/src/main/java/org/owasp/dependencycheck/analyzer/CPEAnalyzer.java index f6121b258..19d9c890d 100644 --- a/dependency-check-core/src/main/java/org/owasp/dependencycheck/analyzer/CPEAnalyzer.java +++ b/dependency-check-core/src/main/java/org/owasp/dependencycheck/analyzer/CPEAnalyzer.java @@ -255,7 +255,7 @@ public class CPEAnalyzer implements Analyzer { protected List searchCPE(String vendor, String product, Set vendorWeightings, Set productWeightings) { - final ArrayList ret = new ArrayList(MAX_QUERY_RESULTS); + final List ret = new ArrayList(MAX_QUERY_RESULTS); final String searchString = buildSearch(vendor, product, vendorWeightings, productWeightings); if (searchString == null) { diff --git a/dependency-check-core/src/main/java/org/owasp/dependencycheck/analyzer/HintAnalyzer.java b/dependency-check-core/src/main/java/org/owasp/dependencycheck/analyzer/HintAnalyzer.java index 123f51f83..2cf2c87c9 100644 --- a/dependency-check-core/src/main/java/org/owasp/dependencycheck/analyzer/HintAnalyzer.java +++ b/dependency-check-core/src/main/java/org/owasp/dependencycheck/analyzer/HintAnalyzer.java @@ -19,6 +19,7 @@ package org.owasp.dependencycheck.analyzer; import java.util.ArrayList; import java.util.Iterator; +import java.util.List; import java.util.Set; import org.owasp.dependencycheck.Engine; import org.owasp.dependencycheck.analyzer.exception.AnalysisException; @@ -101,7 +102,7 @@ public class HintAnalyzer extends AbstractAnalyzer implements Analyzer { dependency.getVendorEvidence().addEvidence("hint analyzer", "vendor", "vmware", Confidence.HIGH); } final Iterator itr = dependency.getVendorEvidence().iterator(); - final ArrayList newEntries = new ArrayList(); + final List newEntries = new ArrayList(); while (itr.hasNext()) { final Evidence e = itr.next(); if ("sun".equalsIgnoreCase(e.getValue(false))) { diff --git a/dependency-check-core/src/main/java/org/owasp/dependencycheck/analyzer/JarAnalyzer.java b/dependency-check-core/src/main/java/org/owasp/dependencycheck/analyzer/JarAnalyzer.java index 34506582f..5adf7968f 100644 --- a/dependency-check-core/src/main/java/org/owasp/dependencycheck/analyzer/JarAnalyzer.java +++ b/dependency-check-core/src/main/java/org/owasp/dependencycheck/analyzer/JarAnalyzer.java @@ -227,7 +227,7 @@ public class JarAnalyzer extends AbstractFileTypeAnalyzer { @Override public void analyzeFileType(Dependency dependency, Engine engine) throws AnalysisException { try { - final ArrayList classNames = collectClassNames(dependency); + final List classNames = collectClassNames(dependency); final String fileName = dependency.getFileName().toLowerCase(); if (classNames.isEmpty() && (fileName.endsWith("-sources.jar") @@ -255,7 +255,7 @@ public class JarAnalyzer extends AbstractFileTypeAnalyzer { * @throws AnalysisException is thrown if there is an exception parsing the pom * @return whether or not evidence was added to the dependency */ - protected boolean analyzePOM(Dependency dependency, ArrayList classes, Engine engine) throws AnalysisException { + protected boolean analyzePOM(Dependency dependency, List classes, Engine engine) throws AnalysisException { boolean foundSomething = false; final JarFile jar; try { @@ -531,7 +531,7 @@ public class JarAnalyzer extends AbstractFileTypeAnalyzer { * file being analyzed * @return true if there was evidence within the pom that we could use; otherwise false */ - private boolean setPomEvidence(Dependency dependency, Model pom, Properties pomProperties, ArrayList classes) { + private boolean setPomEvidence(Dependency dependency, Model pom, Properties pomProperties, List classes) { boolean foundSomething = false; boolean addAsIdentifier = true; if (pom == null) { @@ -659,10 +659,10 @@ public class JarAnalyzer extends AbstractFileTypeAnalyzer { * @param dependency a dependency to analyze * @param addPackagesAsEvidence a flag indicating whether or not package names should be added as evidence. */ - protected void analyzePackageNames(ArrayList classNames, + protected void analyzePackageNames(List classNames, Dependency dependency, boolean addPackagesAsEvidence) { - final HashMap vendorIdentifiers = new HashMap(); - final HashMap productIdentifiers = new HashMap(); + final Map vendorIdentifiers = new HashMap(); + final Map productIdentifiers = new HashMap(); analyzeFullyQualifiedClassNames(classNames, vendorIdentifiers, productIdentifiers); final int classCount = classNames.size(); @@ -704,7 +704,7 @@ public class JarAnalyzer extends AbstractFileTypeAnalyzer { * @return whether evidence was identified parsing the manifest * @throws IOException if there is an issue reading the JAR file */ - protected boolean parseManifest(Dependency dependency, ArrayList classInformation) throws IOException { + protected boolean parseManifest(Dependency dependency, List classInformation) throws IOException { boolean foundSomething = false; JarFile jar = null; try { @@ -1050,8 +1050,8 @@ public class JarAnalyzer extends AbstractFileTypeAnalyzer { * @param dependency the dependency being analyzed * @return an list of fully qualified class names */ - private ArrayList collectClassNames(Dependency dependency) { - final ArrayList classNames = new ArrayList(); + private List collectClassNames(Dependency dependency) { + final List classNames = new ArrayList(); JarFile jar = null; try { jar = new JarFile(dependency.getActualFilePath()); @@ -1089,10 +1089,10 @@ public class JarAnalyzer extends AbstractFileTypeAnalyzer { * @param vendor HashMap of possible vendor names from package names (e.g. owasp) * @param product HashMap of possible product names from package names (e.g. dependencycheck) */ - private void analyzeFullyQualifiedClassNames(ArrayList classNames, - HashMap vendor, HashMap product) { + private void analyzeFullyQualifiedClassNames(List classNames, + Map vendor, Map product) { for (ClassNameInformation entry : classNames) { - final ArrayList list = entry.getPackageStructure(); + final List list = entry.getPackageStructure(); addEntry(vendor, list.get(0)); if (list.size() == 2) { @@ -1120,7 +1120,7 @@ public class JarAnalyzer extends AbstractFileTypeAnalyzer { * @param collection a collection of strings and their occurrence count * @param key the key to add to the collection */ - private void addEntry(HashMap collection, String key) { + private void addEntry(Map collection, String key) { if (collection.containsKey(key)) { collection.put(key, collection.get(key) + 1); } else { @@ -1137,7 +1137,7 @@ public class JarAnalyzer extends AbstractFileTypeAnalyzer { * @param value the value to check to see if it contains a package name * @param evidence the evidence collection to add new entries too */ - private void addMatchingValues(ArrayList classes, String value, EvidenceCollection evidence) { + private void addMatchingValues(List classes, String value, EvidenceCollection evidence) { if (value == null || value.isEmpty() || classes == null || classes.isEmpty()) { return; } diff --git a/dependency-check-core/src/main/java/org/owasp/dependencycheck/data/nvdcve/CveDB.java b/dependency-check-core/src/main/java/org/owasp/dependencycheck/data/nvdcve/CveDB.java index d38da868c..08258d7c6 100644 --- a/dependency-check-core/src/main/java/org/owasp/dependencycheck/data/nvdcve/CveDB.java +++ b/dependency-check-core/src/main/java/org/owasp/dependencycheck/data/nvdcve/CveDB.java @@ -28,6 +28,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.List; +import java.util.Map; import java.util.Map.Entry; import java.util.Properties; import java.util.Set; @@ -458,7 +459,8 @@ public class CveDB { final List vulnerabilities = new ArrayList(); PreparedStatement ps; - final HashSet cveEntries = new HashSet(); + //TODO(code review): Looks like things are only added to this map, but never retrieved or checked + final Set cveEntries = new HashSet(); try { ps = getConnection().prepareStatement(SELECT_CVE_FROM_SOFTWARE); ps.setString(1, cpe.getVendor()); @@ -466,7 +468,7 @@ public class CveDB { rs = ps.executeQuery(); String currentCVE = ""; - final HashMap vulnSoftware = new HashMap(); + final Map vulnSoftware = new HashMap(); while (rs.next()) { final String cveId = rs.getString(1); if (!currentCVE.equals(cveId)) { //check for match and add @@ -787,12 +789,12 @@ public class CveDB { * @param identifiedVersion the identified version of the dependency being analyzed * @return true if the identified version is affected, otherwise false */ - protected Entry getMatchingSoftware(HashMap vulnerableSoftware, String vendor, String product, + protected Entry getMatchingSoftware(Map vulnerableSoftware, String vendor, String product, DependencyVersion identifiedVersion) { final boolean isVersionTwoADifferentProduct = "apache".equals(vendor) && "struts".equals(product); - final HashSet majorVersionsAffectingAllPrevious = new HashSet(); + final Set majorVersionsAffectingAllPrevious = new HashSet(); final boolean matchesAnyPrevious = identifiedVersion == null || "-".equals(identifiedVersion.toString()); String majorVersionMatch = null; for (Entry entry : vulnerableSoftware.entrySet()) { diff --git a/dependency-check-core/src/main/java/org/owasp/dependencycheck/data/nvdcve/DatabaseProperties.java b/dependency-check-core/src/main/java/org/owasp/dependencycheck/data/nvdcve/DatabaseProperties.java index a10fc1d30..8b90dd0fa 100644 --- a/dependency-check-core/src/main/java/org/owasp/dependencycheck/data/nvdcve/DatabaseProperties.java +++ b/dependency-check-core/src/main/java/org/owasp/dependencycheck/data/nvdcve/DatabaseProperties.java @@ -154,7 +154,7 @@ public class DatabaseProperties { * @return a map of the database meta data */ public Map getMetaData() { - final TreeMap map = new TreeMap(); + final Map map = new TreeMap(); for (Entry entry : properties.entrySet()) { final String key = (String) entry.getKey(); if (!"version".equals(key)) { diff --git a/dependency-check-core/src/main/java/org/owasp/dependencycheck/data/nvdcve/DriverLoader.java b/dependency-check-core/src/main/java/org/owasp/dependencycheck/data/nvdcve/DriverLoader.java index fbce2e8a8..127b43673 100644 --- a/dependency-check-core/src/main/java/org/owasp/dependencycheck/data/nvdcve/DriverLoader.java +++ b/dependency-check-core/src/main/java/org/owasp/dependencycheck/data/nvdcve/DriverLoader.java @@ -27,6 +27,7 @@ import java.sql.Driver; import java.sql.DriverManager; import java.sql.SQLException; import java.util.ArrayList; +import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; @@ -75,7 +76,7 @@ public final class DriverLoader { */ public static Driver load(String className, String pathToDriver) throws DriverLoadException { final URLClassLoader parent = (URLClassLoader) ClassLoader.getSystemClassLoader(); - final ArrayList urls = new ArrayList(); + final List urls = new ArrayList(); final String[] paths = pathToDriver.split(File.pathSeparator); for (String path : paths) { final File file = new File(path); diff --git a/dependency-check-core/src/main/java/org/owasp/dependencycheck/utils/DependencyVersionUtil.java b/dependency-check-core/src/main/java/org/owasp/dependencycheck/utils/DependencyVersionUtil.java index a938434be..36991a93c 100644 --- a/dependency-check-core/src/main/java/org/owasp/dependencycheck/utils/DependencyVersionUtil.java +++ b/dependency-check-core/src/main/java/org/owasp/dependencycheck/utils/DependencyVersionUtil.java @@ -18,6 +18,7 @@ package org.owasp.dependencycheck.utils; import java.util.ArrayList; +import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -62,7 +63,7 @@ public final class DependencyVersionUtil { //'-' is a special case used within the CVE entries, just include it as the version. if ("-".equals(text)) { final DependencyVersion dv = new DependencyVersion(); - final ArrayList list = new ArrayList(); + final List list = new ArrayList(); list.add(text); dv.setVersionParts(list); return dv; diff --git a/dependency-check-core/src/main/java/org/owasp/dependencycheck/utils/UrlStringUtils.java b/dependency-check-core/src/main/java/org/owasp/dependencycheck/utils/UrlStringUtils.java index bdec9b3e5..92f7ee71e 100644 --- a/dependency-check-core/src/main/java/org/owasp/dependencycheck/utils/UrlStringUtils.java +++ b/dependency-check-core/src/main/java/org/owasp/dependencycheck/utils/UrlStringUtils.java @@ -23,6 +23,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.HashSet; import java.util.List; +import java.util.Set; import java.util.regex.Pattern; /** @@ -68,7 +69,7 @@ public final class UrlStringUtils { /** * A listing of domain parts that should not be used as evidence. Yes, this is an incomplete list. */ - private static final HashSet IGNORE_LIST = new HashSet( + private static final Set IGNORE_LIST = new HashSet( Arrays.asList("www", "com", "org", "gov", "info", "name", "net", "pro", "tel", "mobi", "xxx")); /** @@ -86,7 +87,7 @@ public final class UrlStringUtils { * @throws MalformedURLException thrown if the URL is malformed */ public static List extractImportantUrlData(String text) throws MalformedURLException { - final ArrayList importantParts = new ArrayList(); + final List importantParts = new ArrayList(); final URL url = new URL(text); final String[] domain = url.getHost().split("\\."); //add the domain except www and the tld.