diff --git a/.gitignore b/.gitignore index 1c55ffdfe..09bf20505 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,6 @@ */target/** +# IntelliJ test run side-effects +dependency-check-core/data/ # Intellij project files *.iml *.ipr diff --git a/dependency-check-core/src/main/java/org/owasp/dependencycheck/dependency/Evidence.java b/dependency-check-core/src/main/java/org/owasp/dependencycheck/dependency/Evidence.java index 1f3d8e40e..fd2c0ce20 100644 --- a/dependency-check-core/src/main/java/org/owasp/dependencycheck/dependency/Evidence.java +++ b/dependency-check-core/src/main/java/org/owasp/dependencycheck/dependency/Evidence.java @@ -26,6 +26,9 @@ import java.io.Serializable; */ public class Evidence implements Serializable, Comparable { + public static final int MAGIC_HASH_INIT_VALUE = 3; + public static final int MAGIC_HASH_MULTIPLIER = 67; + /** * Creates a new Evidence object. */ @@ -176,11 +179,11 @@ public class Evidence implements Serializable, Comparable { */ @Override public int hashCode() { - int hash = 3; - hash = 67 * hash + (this.name != null ? this.name.hashCode() : 0); - hash = 67 * hash + (this.source != null ? this.source.hashCode() : 0); - hash = 67 * hash + (this.value != null ? this.value.hashCode() : 0); - hash = 67 * hash + (this.confidence != null ? this.confidence.hashCode() : 0); + int hash = MAGIC_HASH_INIT_VALUE; + hash = MAGIC_HASH_MULTIPLIER * hash + (this.name != null ? this.name.toLowerCase().hashCode() : 0); + hash = MAGIC_HASH_MULTIPLIER * hash + (this.source != null ? this.source.toLowerCase().hashCode() : 0); + hash = MAGIC_HASH_MULTIPLIER * hash + (this.value != null ? this.value.toLowerCase().hashCode() : 0); + hash = MAGIC_HASH_MULTIPLIER * hash + (this.confidence != null ? this.confidence.hashCode() : 0); return hash; } diff --git a/dependency-check-core/src/test/java/org/owasp/dependencycheck/dependency/EvidenceTest.java b/dependency-check-core/src/test/java/org/owasp/dependencycheck/dependency/EvidenceTest.java index 42a506edd..56b7e6393 100644 --- a/dependency-check-core/src/test/java/org/owasp/dependencycheck/dependency/EvidenceTest.java +++ b/dependency-check-core/src/test/java/org/owasp/dependencycheck/dependency/EvidenceTest.java @@ -19,6 +19,7 @@ package org.owasp.dependencycheck.dependency; import org.junit.Test; import static org.junit.Assert.*; +import static org.hamcrest.CoreMatchers.*; /** * @@ -53,6 +54,14 @@ public class EvidenceTest { assertTrue(instance.equals(that8)); } + @Test + public void testHashcodeContract() throws Exception { + final Evidence titleCase = new Evidence("Manifest", "Implementation-Title", "Spring Framework", Confidence.HIGH); + final Evidence lowerCase = new Evidence("manifest", "implementation-title", "spring framework", Confidence.HIGH); + assertThat(titleCase, is(equalTo(lowerCase))); + assertThat(titleCase.hashCode(), is(equalTo(lowerCase.hashCode()))); + } + /** * Test of compareTo method, of class Evidence. */