<div dir="auto">Hello <span class="gmail_chip gmail_plusreply" dir="auto"><a href="mailto:core-libs-dev@openjdk.org" style="color:#15c;text-decoration:underline">@core-libs-dev</a></span>,<div dir="auto"><br></div><div dir="auto">I have frequently run into the following pothole.</div><div dir="auto"><br></div><div dir="auto">Imagine the following directory setup.</div><div dir="auto"><br></div><div dir="auto">root/folderA/fileX.java</div><div dir="auto">root/folderB/fileY.js</div><div dir="auto">root/folderC/fileZ.html</div><div dir="auto"><br></div><div dir="auto">In this directory, let's say that we run the following code.</div><div dir="auto"><br></div><div dir="auto">Files</div><div dir="auto">.walk(Path.of("root"))</div><div dir="auto">.filter(path -> path.endsWith("html"))</div><div dir="auto">.forEach(System.out::println)</div><div dir="auto">;</div><div dir="auto"><br></div><div dir="auto">One would expect only fileZ.html to be printed out, but nothing does. The reason why is because path.endsWith(String) is effectively an alias for path.endsWith(Path.of(String)). The confusion being that Path.of(someString) is looking for a file or a directory. Thus, since there is neither a file nor a folder called "html", the stream prints out nothing.</div><div dir="auto"><br></div><div dir="auto">This a very easy pothole to fall into, as the method name endsWith is the same as the one for String, thus, people will easily mix it up. And worse yet, depending on what they test with, they can easily confuse themselves into thinking they are good. For example, if I had done "fileZ.html" as my endsWith, I would have returned exactly what was expected, causing me to be misled.</div><div dir="auto"><br></div><div dir="auto">And as a cherry on the top, the syntactic benefit of this method is very little. Wrapping your string in a Path.of() means that you fall under the Path.endsWith(Path) overload, which is more explicit what it does. And at the very least, should give pause to the developer thinking it is doing String comparison, as they have to wrap their String in a Path, causing a moment to think.</div><div dir="auto"><br></div><div dir="auto">So, since this is a low value method and it causes high confusion, I vote that we deprecate it.</div><div dir="auto"><br></div><div dir="auto">Thoughts?</div><div dir="auto"><br></div><div dir="auto">Thank you for your time.</div><div dir="auto">David Alayachew</div></div>