RFR: Check if census endpoint is a URL before trying to parse it as a path.

JornVernee via github.com duke at openjdk.java.net
Thu Jun 27 17:22:53 UTC 2019


On Thu, 27 Jun 2019 17:08:53 GMT, Erik Duveblad via github.com <duke at openjdk.java.net> wrote:

> 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.

I was using `s.matches("^http://")` before, but checking on the URI specification https://tools.ietf.org/html/rfc3986#section-3.1

> Although schemes are case-insensitive, the canonical form is lowercase

That's why I went with the case insensitive regex. If we don't care about case then it's fine to use `startsWith`, but otherwise we'd need to check every combination of upper and lower case, so in that case the regex seems better.


More information about the skara-dev mailing list