new File(parent, child) when child is absolute (original) (raw)

Alan Bateman Alan.Bateman at oracle.com
Sat Apr 27 07:34:17 UTC 2013


On 27/04/2013 04:14, Weijun Wang wrote:

I thought that in this case parent is just ignored and it's still the child itself. Turns out this is not true, and

new File("/tmp", "/etc/passwd") is /tmp/etc/passwd Is this really useful in any way? I agree this isn't always obvious but this is how this method was originally specified (JDK1.1, maybe JDK1.0). I've no doubt that attempting to change it now would cause breakage, particularly Windows where a file path such as "/etc/passwd" is a relative path. Can you use java.nio.file.Path for what you are doing? It has resolve methods that do the right thing.

-Alan.



More information about the core-libs-dev mailing list