Can we deprecate Path.endsWith(String)?

Rob Spoor openjdk at icemanx.nl
Thu Sep 18 18:19:57 UTC 2025


If Path.endsWith(String) and possibly Path.startsWith(String) are 
deprecated, can we then get Path.endsWithPath(String) and 
Path.startsWithPath(String) as replacements? Because having to type 
path.endsWith(path.getFileSystem().getPath(other)) is not only a lot 
more verbose but my IDE also complains that I don't close the result of 
calling path.getFileSystem() (which of course I shouldn't), so I have to 
suppress the warning.


On 18/09/2025 20:08, Brian Burkhalter wrote:
> 
> On Sep 17, 2025, at 8:24 AM, Pavel Rappo <pavel.rappo at gmail.com> wrote:
> 
> FWIW, I too have fallen into this trap, and I did that even more than
> once. When my brain sees Path.endsWith(String), it somehow silently
> assumes that its semantic is that of String.endsWith(String).
> 
> Of course, it isn't. What's worse, I learn about my mistake at
> runtime. But not because of an exception, no; I learn about it by
> getting unexpected results.
> 
> I have filed an issue to improve the specification of this method somehow:
> 
> https://bugs.openjdk.org/browse/JDK-8368007
> 
> There used to be a method that implemented the file extension thingy,
> but the commit was backed out. If it makes its way back in one form or
> another, it might help to avoid the trap:
> 
> One day I might evenutally attempt to push that boulder up the mountain again. Today is not that day.
> 
> Brian



More information about the core-libs-dev mailing list