From b4465b4dd3337f4780cc81a511b996624ee7f0ad Mon Sep 17 00:00:00 2001 From: wreulicke Date: Tue, 11 Sep 2018 13:51:52 +0900 Subject: [PATCH 1/3] simplify hash code calculation --- .../umd/cs/findbugs/classfile/FieldOrMethodDescriptor.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/spotbugs/src/main/java/edu/umd/cs/findbugs/classfile/FieldOrMethodDescriptor.java b/spotbugs/src/main/java/edu/umd/cs/findbugs/classfile/FieldOrMethodDescriptor.java index 8878c0a504a..65fba435166 100644 --- a/spotbugs/src/main/java/edu/umd/cs/findbugs/classfile/FieldOrMethodDescriptor.java +++ b/spotbugs/src/main/java/edu/umd/cs/findbugs/classfile/FieldOrMethodDescriptor.java @@ -19,6 +19,8 @@ package edu.umd.cs.findbugs.classfile; +import java.util.Objects; + import edu.umd.cs.findbugs.internalAnnotations.SlashedClassName; /** @@ -52,7 +54,7 @@ public FieldOrMethodDescriptor(@SlashedClassName String slashedClassName, String } public static int getNameSigHashCode(String name, String signature) { - return name.hashCode() * 3119 + signature.hashCode() * 131; + return Objects.hash(name, signature); } public int getNameSigHashCode() { @@ -132,7 +134,7 @@ protected boolean haveEqualFields(FieldOrMethodDescriptor other) { @Override public final int hashCode() { if (cachedHashCode == 0) { - cachedHashCode = slashedClassName.hashCode() * 7919 + nameSigHashCode + (isStatic ? 1 : 0); + cachedHashCode = Objects.hash(slashedClassName, nameSigHashCode, isStatic); } return cachedHashCode; } From 95f1b89f65c6eb320262e6602225d4e3008b802d Mon Sep 17 00:00:00 2001 From: wreulicke Date: Fri, 14 Sep 2018 11:56:56 +0900 Subject: [PATCH 2/3] add changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 74ce4a3db28..fa08232e14e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ Currently the versioning policy of this project follows [Semantic Versioning v2. ### Fixed * Don't print exit code related output if '-quiet' is passed ([#714](https://github.com/spotbugs/spotbugs/pull/714)) * Don't underflow the stack at INVOKEDYNAMIC when modeling stack frame types ([#500](https://github.com/spotbugs/spotbugs/issues/500)) +* Fix hash code collision ([#751](https://github.com/spotbugs/spotbugs/pull/751)) ### CHANGED * ASM_VERSION=ASM7_EXPERIMENTAL by default to support Java 11 From 747065f5c76231dbdcc367b9f18ee3238685940e Mon Sep 17 00:00:00 2001 From: wreulicke Date: Fri, 14 Sep 2018 18:27:56 +0900 Subject: [PATCH 3/3] move entry --- CHANGELOG.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fa08232e14e..97eaa28a417 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,12 +9,14 @@ Currently the versioning policy of this project follows [Semantic Versioning v2. ### CHANGED * Start migrating STDOUT/STDERR usage to a logging framework +### Fixed +* Fix hash code collision ([#751](https://github.com/spotbugs/spotbugs/pull/751)) + ## 3.1.7 - 2018-09-12 ### Fixed * Don't print exit code related output if '-quiet' is passed ([#714](https://github.com/spotbugs/spotbugs/pull/714)) * Don't underflow the stack at INVOKEDYNAMIC when modeling stack frame types ([#500](https://github.com/spotbugs/spotbugs/issues/500)) -* Fix hash code collision ([#751](https://github.com/spotbugs/spotbugs/pull/751)) ### CHANGED * ASM_VERSION=ASM7_EXPERIMENTAL by default to support Java 11