RFR: 8057113: (fs) Path should have a method to obtain the filename extension [v6]

Brian Burkhalter bpb at openjdk.java.net
Fri Apr 29 23:34:38 UTC 2022


On Fri, 29 Apr 2022 15:48:32 GMT, Roger Riggs <rriggs at openjdk.org> wrote:

>> Brian Burkhalter has updated the pull request incrementally with one additional commit since the last revision:
>> 
>>   8057113: String getExtension(String defaultExtension) to Optional<String> getExtension() and other changes
>
> src/java.base/share/classes/java/nio/file/Path.java line 378:
> 
>> 376:         if (thisExtension == null)
>> 377:             return extension.isEmpty() ?
>> 378:                 this : fs.getPath(thisPath + "." + extension);
> 
> Can this end up with a double dot ".." in the case where the original path ended in in dot?
> I.e.
> 
>     Path p = Path.of("foo.");
>     Path q = p.replaceExtension("bar");

Unfortunately the result of the above is currently `foo..bar`. If a Path which ends in a dot is considered to have `""` as an extension instead of `Optional.empty()`, that might simplify this case. Needs further scrutiny.

-------------

PR: https://git.openjdk.java.net/jdk/pull/8066


More information about the nio-dev mailing list