diff options
author | Reinier Zwitserloot <reinier@zwitserloot.com> | 2015-06-25 00:13:12 +0200 |
---|---|---|
committer | Reinier Zwitserloot <reinier@zwitserloot.com> | 2015-06-25 00:13:12 +0200 |
commit | 251fd03cd78ef6996d4252450bda596a5e8b11b9 (patch) | |
tree | 6cd9f4a8510ffabed01cd5eae60c0e1b6f2d2b35 /src/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java | |
parent | 23dcc9f5a5f3c24ccfb2f98ab556daed0dee3c89 (diff) | |
download | lombok-251fd03cd78ef6996d4252450bda596a5e8b11b9.tar.gz lombok-251fd03cd78ef6996d4252450bda596a5e8b11b9.tar.bz2 lombok-251fd03cd78ef6996d4252450bda596a5e8b11b9.zip |
The hashCode() method now generates a magic prime instead of 0 for the hash of null values; this reduces collisions.
Diffstat (limited to 'src/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java')
-rw-r--r-- | src/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/src/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java b/src/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java index 7e2ff513..77fe3a52 100644 --- a/src/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java +++ b/src/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java @@ -358,7 +358,7 @@ public class HandleEqualsAndHashCode extends EclipseAnnotationHandler<EqualsAndH statements.add(createResultCalculation(source, fieldAccessor)); } else /* objects */ { /* final java.lang.Object $fieldName = this.fieldName; */ - /* $fieldName == null ? 0 : $fieldName.hashCode() */ + /* $fieldName == null ? NULL_PRIME : $fieldName.hashCode() */ statements.add(createLocalDeclaration(source, dollarFieldName, generateQualifiedTypeRef(source, TypeConstants.JAVA_LANG_OBJECT), fieldAccessor)); SingleNameReference copy1 = new SingleNameReference(dollarFieldName, p); @@ -375,8 +375,8 @@ public class HandleEqualsAndHashCode extends EclipseAnnotationHandler<EqualsAndH setGeneratedBy(nullLiteral, source); EqualExpression objIsNull = new EqualExpression(copy2, nullLiteral, OperatorIds.EQUAL_EQUAL); setGeneratedBy(objIsNull, source); - IntLiteral int0 = makeIntLiteral("0".toCharArray(), source); - ConditionalExpression nullOrHashCode = new ConditionalExpression(objIsNull, int0, hashCodeCall); + IntLiteral intMagic = makeIntLiteral(String.valueOf(HandlerUtil.primeForNull()).toCharArray(), source); + ConditionalExpression nullOrHashCode = new ConditionalExpression(objIsNull, intMagic, hashCodeCall); nullOrHashCode.sourceStart = pS; nullOrHashCode.sourceEnd = pE; setGeneratedBy(nullOrHashCode, source); statements.add(createResultCalculation(source, nullOrHashCode)); |