From e2f78ee1cadab056d381a0047006f39899055556 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Kubitz?= Date: Fri, 6 Dec 2024 14:29:53 +0100 Subject: [PATCH] TypeBinding: What happens without custom hash()? https://github.com/eclipse-jdt/eclipse.jdt.core/issues/3412 --- Jenkinsfile | 5 +---- .../compiler/lookup/ArrayBinding.java | 5 ----- .../compiler/lookup/LocalTypeBinding.java | 4 ---- .../compiler/lookup/ReferenceBinding.java | 9 --------- .../internal/compiler/lookup/TypeSystem.java | 20 +++---------------- .../compiler/lookup/WildcardBinding.java | 5 ----- 6 files changed, 4 insertions(+), 44 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index d6309cba57f..5baed71f931 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -27,9 +27,7 @@ pipeline { # The max heap should be specified for tycho explicitly # via configuration/argLine property in pom.xml # export MAVEN_OPTS="-Xmx2G" - - mvn clean install -f org.eclipse.jdt.core.compiler.batch -DlocalEcjVersion=99.99 -Dmaven.repo.local=$WORKSPACE/.m2/repository -DcompilerBaselineMode=disable -DcompilerBaselineReplace=none - + mvn -U clean verify --batch-mode --fail-at-end -Dmaven.repo.local=$WORKSPACE/.m2/repository \ -Ptest-on-javase-23 -Pbree-libs -Papi-check -Pjavadoc -Pp2-repo \ -Dmaven.test.failure.ignore=true \ @@ -39,7 +37,6 @@ pipeline { -DDetectVMInstallationsJob.disabled=true \ -Dtycho.apitools.debug \ -Dtycho.debug.artifactcomparator \ - -Dcbi-ecj-version=99.99 """ } post { diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/ArrayBinding.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/ArrayBinding.java index fd0685a7bc8..c45432396a6 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/ArrayBinding.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/ArrayBinding.java @@ -258,11 +258,6 @@ public PackageBinding getPackage() { return this.leafComponentType.getPackage(); } -@Override -public int hashCode() { - return this.leafComponentType == null ? super.hashCode() : this.leafComponentType.hashCode(); -} - /* Answer true if the receiver type can be assigned to the argument type (right) */ @Override diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/LocalTypeBinding.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/LocalTypeBinding.java index 3ff27dde94e..8bb420afd0c 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/LocalTypeBinding.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/LocalTypeBinding.java @@ -165,10 +165,6 @@ public TypeBinding clone(TypeBinding outerType) { return copy; } -@Override -public int hashCode() { - return this.enclosingType.hashCode(); -} /* * Overriden for code assist. In this case, the constantPoolName() has not been computed yet. * Slam the source name so that the signature is syntactically correct. diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/ReferenceBinding.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/ReferenceBinding.java index 33286162ac6..d76bf903257 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/ReferenceBinding.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/ReferenceBinding.java @@ -1204,15 +1204,6 @@ public TypeVariableBinding getTypeVariable(char[] variableName) { return null; } -@Override -public int hashCode() { - // ensure ReferenceBindings hash to the same position as UnresolvedReferenceBindings so they can be replaced without rehashing - // ALL ReferenceBindings are unique when created so equals() is the same as == - return (this.compoundName == null || this.compoundName.length == 0) - ? super.hashCode() - : CharOperation.hashCode(this.compoundName[this.compoundName.length - 1]); -} - final int identityHashCode() { return super.hashCode(); } diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/TypeSystem.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/TypeSystem.java index c7de83d7eaa..9634ce2e83a 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/TypeSystem.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/TypeSystem.java @@ -19,7 +19,9 @@ *******************************************************************************/ package org.eclipse.jdt.internal.compiler.lookup; +import java.util.Arrays; import java.util.HashMap; +import java.util.Objects; import java.util.function.Consumer; import java.util.function.Supplier; import org.eclipse.jdt.internal.compiler.ast.ASTNode; @@ -133,25 +135,9 @@ public boolean equals(Object other) { PTBKey that = (PTBKey) other; // homogeneous container. return this.type == that.type && this.enclosingType == that.enclosingType && Util.effectivelyEqual(this.arguments, that.arguments); //$IDENTITY-COMPARISON$ } - final int hash(TypeBinding b) { - if(b instanceof WildcardBinding || b instanceof TypeVariableBinding || b.getClass() == ParameterizedTypeBinding.class) { - return System.identityHashCode(b); - } - return b.hashCode(); - } @Override public int hashCode() { - final int prime=31; - int hashCode = 1 + hash(this.type); - if (this.enclosingType != null && this.enclosingType.getClass() == ParameterizedTypeBinding.class) { - // Note: this works as in swapUnresolved, a null enclosingType is never replaced by a - // ParameterizedTypeBinding (just by a non-generic or RawTypeBinding) - hashCode = hashCode * prime + System.identityHashCode(this.enclosingType); - } - for (int i = 0, length = this.arguments == null ? 0 : this.arguments.length; i < length; i++) { - hashCode = hashCode * prime + hash(this.arguments[i]); - } - return hashCode; + return Objects.hash(this.type, this.enclosingType, Arrays.hashCode(this.arguments)); } } diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/WildcardBinding.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/WildcardBinding.java index 2a69d855e28..1134e500d8e 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/WildcardBinding.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/WildcardBinding.java @@ -614,11 +614,6 @@ public char[] genericTypeSignature() { return this.genericSignature; } - @Override - public int hashCode() { - return this.genericType.hashCode(); - } - @Override public boolean hasTypeBit(int bit) { if (this.typeBits == TypeIds.BitUninitialized) {