RFR: 8290047: (fs) FileSystem.getPathMatcher needlessly checks syntaxAndInput.length

Roger Riggs rriggs at openjdk.org
Thu Jul 21 17:17:48 UTC 2022


On Thu, 21 Jul 2022 15:29:10 GMT, Brian Burkhalter <bpb at openjdk.org> wrote:

> For a `String` “s”, `s.indexOf(int)` can never return a value `>= s.length()` so change the check
> 
>         int pos = syntaxAndInput.indexOf(':');
>         if (pos <= 0 || pos == syntaxAndInput.length())
> 
> to
> 
>         if (pos <= 0)

src/java.base/share/classes/jdk/internal/jrtfs/JrtFileSystem.java line 178:

> 176:     public PathMatcher getPathMatcher(String syntaxAndInput) {
> 177:         int pos = syntaxAndInput.indexOf(':');
> 178:         if (pos <= 0 || pos == syntaxAndInput.length()) {

Is this really a different bug? Should it be checking for `length() - 1` to throw IAE.
That would then throw if there was no string after the syntax selector;  for example "glob:"

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

PR: https://git.openjdk.org/jdk/pull/9595


More information about the core-libs-dev mailing list