You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cocoon.apache.org by Ugo Cei <ug...@apache.org> on 2004/04/19 00:44:48 UTC
IOUtils testcase failing
Our latest CVS head has (at least) one failing testcase:
Testcase: testNormalizedFilename took 0,158 sec
Caused an ERROR
0
java.lang.ArrayIndexOutOfBoundsException: 0
at
org.apache.cocoon.util.IOUtils.normalizedFilename(IOUtils.java:203)
at
org.apache.cocoon.util.test.IOUtilsTestCase.testNormalizedFilename(IOUti
lsTestCase.java:80)
I gave a look at the IOUtils and IOUtilsTestCase classes and it looks
like they haven't changed in quite some time, so the problem lies
somewhere else.
public static String normalizedFilename(String filename) {
if(File.separatorChar == '\\')
filename = filename.replace('/','\\');
else
filename = filename.replace('\\','/');
String[] path = StringUtils.split(filename, File.separator);
int start = (path[0].length() == 0) ? 1 : 0;
The last line is line 203 and the error happens when the method is
invoked with an empty string as its argument. According to the API
docs, the StringUtils.split function returns an empty array when
invoked with an empty string argument. Thus, referencing path[0] causes
an AIOOB exception. So, the problem is clear, and the fix should be
easy.
What I'd like to know is: when did this test start failing? Probably
after an upgrade to commons-lang, it seems. Then, why do we never
bother to run our (very limited) test suite before committing a patch?
Ugo