String.indexOf(String, int) bug

Colin Stevens cstevens at
Wed May 26 17:29:58 PDT 1999

String.indexOf(String str, int offset) crashes if str is a 0-length string,
since the implmentation always dereferences at least one character in the 
string.  A Q&D solution is to change String.indexOf(String, int) to check if 
"str" is length 0 (and then return 0) at the beginning.

Run this:

public class foo {
    public static void
    main(String[] args)
        throws Exception
        String src = "abcdefghijklmnopqrstuvwxyz";
        int index = src.indexOf("");


get this:

        at java.lang.String.indexOf(
        at java.lang.String.indexOf(
        at foo.main(

More information about the kaffe mailing list