commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Stephen Colebourne (JIRA)" <>
Subject [jira] Commented: (IO-128) NPE on FilenameUtils.equalsNormalizedOnSystem()
Date Sat, 13 Oct 2007 08:03:50 GMT


Stephen Colebourne commented on IO-128:

I believe that the intention was that all invalid inputs would result in null, not an exception,
so the fix is incorrect. (But it should also not throw NPE)

A double slash at the start is taken to refer to a UNC server name. Since //file.txt isn't
sufficient for a UNC server name, the getPrefixLength method returns null.

Two options: 
a) clarify that if the double slash is at the start, it has to refer to a UNC name
b) handle the case that a double slash at the start should be just normalized to a single
slash if it is not a UNC name.

(b) is probably better. Effectively you need to convert // to / before getting the prefix
in this scenario.

> NPE on FilenameUtils.equalsNormalizedOnSystem()
> -----------------------------------------------
>                 Key: IO-128
>                 URL:
>             Project: Commons IO
>          Issue Type: Bug
>          Components: Utilities
>    Affects Versions: 1.2, 1.3, 1.3.1, 1.3.2
>            Reporter: Antonio Gallardo
>            Assignee: Niall Pemberton
>             Fix For: 1.4
> The following code in commons-io (1.3.2) throws an NPE exception:
>     .equalsNormalizedOnSystem(
>             "//a.html",
>             "//ab.html");
> And here is the exception:
> java.lang.NullPointerException: The strings must not be null
>    at
>    at
>    at
>    at
>    at org.eclipse.jdt.internal.debug.ui.snippeteditor.ScrapbookMain1.eval(
>    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>    at sun.reflect.NativeMethodAccessorImpl.invoke(
>    at sun.reflect.DelegatingMethodAccessorImpl.invoke(
>    at java.lang.reflect.Method.invoke(
>    at org.eclipse.jdt.internal.debug.ui.snippeteditor.ScrapbookMain.evalLoop(
>    at org.eclipse.jdt.internal.debug.ui.snippeteditor.ScrapbookMain.main(
> I think it is wrong a message "The strings must not be null", since there is not a null
string involved in the call.
> Interesting is if both or 1 of the strings is null, it did not throws an exception.
> Additional comment from Niall Pemberton (on the dev mail list):
> The problem is that the FilenameUtils's normalize(String) method
> returns "null" if it thinks the file names are invalid - which in your
> case it seems to be doing so for both file names.
> So I guess theres two issues here - you're right the error is
> misleading and FilenameUtils should check the names again after
> calling normalize() for nulls and throw a more appropriate message.

This message is automatically generated by JIRA.
You can reply to this email to add a comment to the issue online.

View raw message