From 6ddb8c839c4fee8523b4cea6d09ad7bc2a10d30b Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Wed, 1 Aug 2007 17:46:05 -0600 Subject: [PATCH] check identities in String.equals(), etc. --- classpath/java/lang/String.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/classpath/java/lang/String.java b/classpath/java/lang/String.java index aa7f672fc7..fd278d8320 100644 --- a/classpath/java/lang/String.java +++ b/classpath/java/lang/String.java @@ -65,14 +65,16 @@ public final class String implements Comparable { } public boolean equals(Object o) { - return o instanceof String && compareTo((String) o) == 0; + return this == o || (o instanceof String && compareTo((String) o) == 0); } public boolean equalsIgnoreCase(String s) { - return compareToIgnoreCase(s) == 0; + return this == s || compareToIgnoreCase(s) == 0; } public int compareTo(String s) { + if (this == s) return 0; + int d = length - s.length; if (d != 0) { return d; @@ -88,6 +90,8 @@ public final class String implements Comparable { } public int compareToIgnoreCase(String s) { + if (this == s) return 0; + int d = length - s.length; if (d != 0) { return d;