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]

[PATCH] java.util.StringTokenizer assumes order of parameter evaluation


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/

------------------------ 8< ------------------------------
Hi!

I have tried out the win32 gcj 3.2 binaries, and compiled approx 250,000
lines of code. Mostly it seems to work.
There is one bug in StringTokenizer :

code
>>>>>>

StringTokenizer tkz = new StringTokenizer("test/this/string","/",true);
while (tkz.hasMoreElements())
{
  System.out.print("["+tkz.nextToken()+"] ");
}

<<<<<<

this code should produce :

[test] [/] [this] [/] [string]

But instead it produces :

[test] [] [this] [] [string]



StringTokenizer also fails to work properly when delimiters is not
returned as tokens.


Regards
Lars Andersen
------------------------ 8< ------------------------------




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