RFR: Check if census endpoint is a URL before trying to parse it as a path.
Erik Duveblad via github.com
duke at openjdk.java.net
Thu Jun 27 17:08:53 UTC 2019
On Thu, 27 Jun 2019 14:21:00 GMT, JornVernee via github.com <duke at openjdk.java.net> wrote:
> When running `git jcheck --local` I'm getting the following exception:
>
> ```
> Exception in thread "main" java.nio.file.InvalidPathException: Illegal char <:> at index 5: https://openjdk.java.net/census.xml
> at java.base/sun.nio.fs.WindowsPathParser.normalize(WindowsPathParser.java:182)
> at java.base/sun.nio.fs.WindowsPathParser.parse(WindowsPathParser.java:153)
> at java.base/sun.nio.fs.WindowsPathParser.parse(WindowsPathParser.java:77)
> at java.base/sun.nio.fs.WindowsPath.parse(WindowsPath.java:92)
> at java.base/sun.nio.fs.WindowsFileSystem.getPath(WindowsFileSystem.java:229)
> at java.base/java.nio.file.Path.of(Path.java:147)
> at org.openjdk.skara.cli/org.openjdk.skara.cli.GitJCheck.main(GitJCheck.java:159)
> at org.openjdk.skara.cli/org.openjdk.skara.cli.GitSkara.main(GitSkara.java:130)
> ```
>
> Looking into the source code this seems to be because the fallback endpoint for getting the OpenJDK census is used, a URL, which is not a valid path (at least not on Windows), so the check to see if we're dealing with a path or not fails when parsing the path.
>
> This PR switches to a regular expression for checking whether the endpoint is a URL or not (by checking if it starts with `http(s)://`).
>
> ----------------
>
> Commits:
> - dbccc100: Check if census endpoint is a URL before trying to parse it as a path.
>
> Pull request:
> http://git.openjdk.java.net/skara/pull/10
>
> Webrev:
> https://openjdk.github.io/cr/skara/10/webrev.00
>
> Patch:
> http://git.openjdk.java.net/skara/pull/10.diff
>
> Fetch command:
> git fetch https://github.com/openjdk/skara.git dbccc100:pr/10
cli/src/main/java/org/openjdk/skara/cli/GitJCheck.java line 32:
> 31: import org.openjdk.skara.vcs.openjdk.CommitMessageParsers;
> 32:
> 33: import java.io.IOException;
The regex solution works fine, I just tend to stick with `String::startsWith` for simple cases :smiley:
What do you think of `return s.startsWith("http://") || s.startsWith("https://");` ? I'm fine with the regex if you prefer that.
cli/src/main/java/org/openjdk/skara/cli/GitJCheck.java line 31:
> 30: import org.openjdk.skara.vcs.*;
> 31: import org.openjdk.skara.vcs.openjdk.CommitMessageParsers;
> 32:
Nice to add a static method. Very minor nit, I would probably just have went with `String s` here, but I'm fine with `pathOrURL` as well.
More information about the skara-dev
mailing list