Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrey Loskutov2017-10-28 07:04:11 +0000
committerAndrey Loskutov2017-11-22 08:10:00 +0000
commit903cb9c98a1ec2c69c07c48f4b0ff0c985569d89 (patch)
treeec23223cd996bd622bcf30e34ade137cd258de7e
parent49307556c401e403b16280c49eb69fbdfff6300b (diff)
downloadeclipse.jdt.core-903cb9c98a1ec2c69c07c48f4b0ff0c985569d89.tar.gz
eclipse.jdt.core-903cb9c98a1ec2c69c07c48f4b0ff0c985569d89.tar.xz
eclipse.jdt.core-903cb9c98a1ec2c69c07c48f4b0ff0c985569d89.zip
Bug 526591 - fix "using hashCode() on array"
Calling hashCode() on an array returns the same value as System.identityHashCode(), and ignores the contents of the array. If this happens in hashCode() method of a class implementing equals() and the class uses the array content for equals(), it will break the contract of the hashCode() method saying that equal objects should return same hash value. Change-Id: I0a986c0e5ed6e441588540001efb4ada35b2dbbd Signed-off-by: Andrey Loskutov <loskutov@gmx.de>
-rw-r--r--org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/BasicModule.java2
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/classfmt/ModuleInfo.java4
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/codegen/StackMapFrameCodeStream.java2
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/env/ModuleReferenceImpl.java2
4 files changed, 5 insertions, 5 deletions
diff --git a/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/BasicModule.java b/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/BasicModule.java
index 18a7f96b23..663f7cbfc8 100644
--- a/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/BasicModule.java
+++ b/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/BasicModule.java
@@ -228,7 +228,7 @@ public class BasicModule implements IModule {
@Override
public int hashCode() {
int result = 17;
- int c = this.name.hashCode();
+ int c = CharOperation.hashCode(this.name);
result = 31 * result + c;
c = Arrays.hashCode(this.requires);
result = 31 * result + c;
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/classfmt/ModuleInfo.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/classfmt/ModuleInfo.java
index d46cc0563e..074b708865 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/classfmt/ModuleInfo.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/classfmt/ModuleInfo.java
@@ -288,7 +288,7 @@ public class ModuleInfo extends ClassFileStruct implements IBinaryModule {
}
@Override
public int hashCode() {
- return this.refName.hashCode();
+ return CharOperation.hashCode(this.refName);
}
@Override
public int getModifiers() {
@@ -352,7 +352,7 @@ public class ModuleInfo extends ClassFileStruct implements IBinaryModule {
@Override
public int hashCode() {
int result = 17;
- int c = this.name.hashCode();
+ int c = CharOperation.hashCode(this.name);
result = 31 * result + c;
c = Arrays.hashCode(this.requires);
result = 31 * result + c;
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/codegen/StackMapFrameCodeStream.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/codegen/StackMapFrameCodeStream.java
index 6f2630cfa7..618810ec56 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/codegen/StackMapFrameCodeStream.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/codegen/StackMapFrameCodeStream.java
@@ -54,7 +54,7 @@ public class StackMapFrameCodeStream extends CodeStream {
return false;
}
public int hashCode() {
- return this.pc + this.constantPoolName.hashCode();
+ return this.pc + CharOperation.hashCode(this.constantPoolName);
}
public String toString() {
StringBuffer buffer = new StringBuffer();
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/env/ModuleReferenceImpl.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/env/ModuleReferenceImpl.java
index 15ecf02474..a45efe5c04 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/env/ModuleReferenceImpl.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/env/ModuleReferenceImpl.java
@@ -31,7 +31,7 @@ public class ModuleReferenceImpl implements IModule.IModuleReference {
}
@Override
public int hashCode() {
- return this.name.hashCode();
+ return CharOperation.hashCode(this.name);
}
@Override
public int getModifiers() {

Back to the top