This is the mail archive of the java-patches@gcc.gnu.org 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]
Other format: [Raw text]

Re: [PATCH] java.util.StringTokenizer assumes order of parameterevaluation


Sorry guys, but I just referred to the JLS (section 15.12.4.2,
"Evaluate Arguments"):

http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#45449

and I quote:

"The argument expressions are evaluated in order, from left to right..."

Therefore, the coder for StringTokenizer *can* assume the
order of evaluation - there must be some other problem that
I need to figure out.

BTW, does GCJ guarantee this order at all times? (I just saw
Andrew Haley's patch for a fix for *static* method invocation,
but the StringTokenizer problem is in a member method.)

Sincerely Yours,
Ranjit.

Ranjit Mathew wrote:
Hi,

    Lars Andersen recently pointed out a bug to me
in the class java.util.StringTokenizer in GCJ 3.2 for
Windows that I ultimately traced to a trivial oversight
in the class's code - it assumes the order in which
parameters are evaluated in code like:

    return str.substring(pos, ++pos);

The class works fine at least with GCJ 3.2 on Solaris
but not on Windows. I *think* this is the problem, but
I could very well be mistaken - the problem disappears
if I make this change though.

In any case, here's the patch:
------------------------ 8< ------------------------------
--- StringTokenizer.java.orig   Wed Oct 16 12:14:20 2002
+++ StringTokenizer.java        Wed Oct 16 12:16:35 2002
@@ -182,5 +182,9 @@
       {
         if (retDelims)
-          return str.substring(pos, ++pos);
+         {
+           String retVal = str.substring(pos, pos+1);
+           pos++;
+           return retVal;
+         }
         while (++pos < len && delim.indexOf(str.charAt(pos)) >= 0);
       }
------------------------ 8< ------------------------------

There's more code in the class which makes such assumption
and possibly these are there in other classes as well.

I'm attaching Lars's original mail at the end of this mail
for your reference.

Sincerely Yours,
Ranjit.


--
Ranjit Mathew          Email: rmathew AT hotmail DOT com

Bangalore, INDIA.      Web: http://ranjitmathew.tripod.com/




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