Index: /luni/src/main/java/java/lang/String.java =================================================================== --- /luni/src/main/java/java/lang/String.java (revision 395114) +++ /luni/src/main/java/java/lang/String.java (working copy) @@ -40,7 +40,7 @@ * * @see StringBuffer */ -public final class String implements Serializable, Comparable, CharSequence { +public final class String implements Serializable, Comparable, CharSequence { private static final long serialVersionUID = -6849794470754667710L; /** @@ -94,7 +94,7 @@ * CaseInsensitiveComparator compares Strings ignoring the case of the * characters. */ - private static final class CaseInsensitiveComparator implements Comparator, + private static final class CaseInsensitiveComparator implements Comparator, Serializable { private static final long serialVersionUID = 8575799808933029326L; @@ -111,8 +111,8 @@ * @exception ClassCastException * when objects are not the correct type */ - public int compare(Object o1, Object o2) { - return ((String) o1).compareToIgnoreCase((String) o2); + public int compare(String o1, String o2) { + return o1.compareToIgnoreCase(o2); } } @@ -119,7 +119,7 @@ /* * A Comparator which compares Strings ignoring the case of the characters. */ - public static final Comparator CASE_INSENSITIVE_ORDER = new CaseInsensitiveComparator(); + public static final Comparator CASE_INSENSITIVE_ORDER = new CaseInsensitiveComparator(); private static final char[] ascii; @@ -506,22 +506,6 @@ } /** - * Compare the receiver to the specified Object to determine the relative - * ordering. - * - * @param object - * an Object - * @return an int < 0 if this String is less than the specified String, 0 if - * they are equal, and > 0 if this String is greater - * - * @throws ClassCastException - * when object is not a String - */ - public int compareTo(Object object) { - return compareTo((String) object); - } - - /** * Compares the specified String to this String using the Unicode values of * the characters. Answer 0 if the strings contain the same characters in * the same order. Answer a negative integer if the first non-equal Index: /luni/src/main/java/java/util/Comparator.java =================================================================== --- /luni/src/main/java/java/util/Comparator.java (revision 394551) +++ /luni/src/main/java/java/util/Comparator.java (working copy) @@ -15,12 +15,13 @@ package java.util; - /** * Comparator is used to compare two objects to determine their ordering in * respect to each other. + * + * @since 1.2 */ -public interface Comparator { +public interface Comparator { /** * Compare the two objects to determine the relative ordering. * @@ -34,7 +35,7 @@ * @exception ClassCastException * when objects are not the correct type */ - public int compare(Object object1, Object object2); + public int compare(T object1, T object2); /** * Compares the argument to the receiver, and answers true if they represent Index: /luni/src/test/java/tests/api/java/lang/StringTest.java =================================================================== --- /luni/src/test/java/tests/api/java/lang/StringTest.java (revision 394878) +++ /luni/src/test/java/tests/api/java/lang/StringTest.java (working copy) @@ -181,23 +181,6 @@ } /** - * @tests java.lang.String#compareTo(java.lang.Object) - */ - public void test_compareToLjava_lang_Object() { - // Test for method int java.lang.String.compareTo(java.lang.Object) - String s = "VV"; - assertTrue("Comparison failed for same strings", s - .compareTo((Object) s) == 0); - try { - s.compareTo(new Object()); - } catch (ClassCastException e) { - // Correct - return; - } - fail("Failed to throw exception when compared to non String"); - } - - /** * @tests java.lang.String#compareTo(java.lang.String) */ public void test_compareToLjava_lang_String() { @@ -210,6 +193,12 @@ .compareTo("aaaaab") > 0); assertTrue("Considered case to not be of importance", !("A" .compareTo("a") == 0)); + + try { + "fixture".compareTo(null); + fail("No NPE"); + } catch (NullPointerException e) { + } } /** @@ -244,6 +233,12 @@ } finally { Locale.setDefault(defLocale); } + + try { + "fixture".compareToIgnoreCase(null); + fail("No NPE"); + } catch (NullPointerException e) { + } } /**