8066943: (fs) Path.relativize() gives incorrect result for ".."

Pavel Rappo pavel.rappo at oracle.com
Wed Aug 24 19:28:24 UTC 2016


Hi Alan,

You don't like "for" loops, do you? :-)

    for (int i = 0; i < getNameCount(); i++) {
        ...
    }
    
instead of:

    int n = getNameCount();
    int i = 0;
    while (i < n) {
        ...
        i++;
    }

I'm looking forward to update to the latest TestNg or (to providing a similar
functionality in our test library). When things like:

    try {
        Path result = path.relativize(that);
        out.format("\tExpected: IllegalArgumentException");
        out.format("\tActual: %s\n",  result);
        fail();
    } catch (IllegalArgumentException expected) { }

will become something like:

    assertThrows(IllegalArgumentException.class () -> path.relativize(that));

P.S. Looks good to me! Thanks.

> On 24 Aug 2016, at 20:12, Alan Bateman <Alan.Bateman at oracle.com> wrote:
> 
> The relativize method has been problematic for sometime when used with paths containing "." or "..". Normalizing the paths first will make it work for most cases but there are corner cases that are still not right. The following patch updates the implementations to do the right thing.
> 
>   http://cr.openjdk.java.net/~alanb/8066943/webrev/
> 
> The bulk of the changes are new tests to make sure that all the cases are covered.
> 
> -Alan
> 



More information about the nio-dev mailing list