This is the mail archive of the java-patches@sourceware.cygnus.com mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

PATCH: Boolean.valueOf(), String.equalsIgnoreCase(), String.concat()


Two of these fixes were required to get Volano running.
Boolean.valueOf() and String.equalsIgnoreCase() should both return false
when given a null argument. I have verified this against the JDK's
behavior. We should probibly sit down and audit java.lang for these
bugs, there are likely to be more...

Also, the JDK 1.2 doc says for String.concat() "If the length of the
argument string is 0, then this String object is returned.". The current
implementation doesn't seem to do this.

OK to commit?

regards

  [ bryce ]

1999-12-02  Bryce McKinlay  <bryce@albatross.co.nz>

        * java/lang/natString.cc (equalsIgnoreCase): return false if
        anotherString is null.
        (concat): return `this' if argument has zero length.
        * java/lang/Boolean.java (valueOf): return FALSE if argument is
        null.

Index: java/lang/natString.cc
===================================================================
RCS file: /cvs/java/libgcj/libjava/java/lang/natString.cc,v
retrieving revision 1.7
diff -u -r1.7 natString.cc
--- natString.cc	1999/09/10 22:03:08	1.7
+++ natString.cc	1999/12/02 11:22:54
@@ -524,7 +524,7 @@
 jboolean
 java::lang::String::equalsIgnoreCase (jstring anotherString)
 {
-  if (count != anotherString->count)
+  if (anotherString == NULL || count != anotherString->count)
     return false;
   register jchar *tptr = JvGetStringChars (this);
   register jchar *optr = JvGetStringChars (anotherString);
@@ -705,6 +705,8 @@
   jint str_count = str->count;
   if (str_count == 0)
     return this;
+  if (count == 0)
+    return str;
   jstring result = JvAllocString(count + str_count);
   register jchar *dstPtr = JvGetStringChars(result);
   register jchar *srcPtr = JvGetStringChars(this);
Index: java/lang/Boolean.java
===================================================================
RCS file: /cvs/java/libgcj/libjava/java/lang/Boolean.java,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 Boolean.java
--- Boolean.java	1999/04/07 14:52:37	1.1.1.1
+++ Boolean.java	1999/12/02 11:22:54
@@ -89,7 +89,10 @@
 
   public static Boolean valueOf(String str)
   {
-    /* This returns a Boolean (big B), not a boolean (little b). */
-    return str.equalsIgnoreCase("true") ? TRUE : FALSE;
+    if (str == null)
+      return FALSE;
+    else
+      /* This returns a Boolean (big B), not a boolean (little b). */
+      return str.equalsIgnoreCase("true") ? TRUE : FALSE;
   }
 }

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]