Odd result with canonical paths with intermixed usage of java.io.File and java.nio.file.Files APIs

Alan Bateman Alan.Bateman at oracle.com
Mon Dec 11 16:13:16 UTC 2017

On 11/12/2017 15:46, Jaikiran Pai wrote:
> Thanks Alan. Given that the cache itself is being planned to be 
> eventually removed, that answers the main part of my question and I 
> can workaround this issue in a couple of ways (disabling the cache 
> using that system property is one way) in the application, till that 
> time.
> The only remaining part that I'm curious about is this:
> > ... would it be a better idea (as an application developer) to use 
> Path.toRealPath[2] instead of using the File.getCanonicalPath()? Are 
> these 2 APIs semantically equivalent? The File.getCanonicalPath() 
> talks about the canonical path being "unique" paths but the 
> Path.toRealPath has no such mentions.
The main semantic difference is that toRealPath method can only return 
the real path of existing file (the file must exist). I don't know if 
that helps with your scenario or not.


More information about the core-libs-dev mailing list