RFR: 1878: Improve argument check in SKARA CLI

Zhao Song zsong at openjdk.org
Fri Apr 14 16:10:17 UTC 2023

On Fri, 14 Apr 2023 12:42:54 GMT, Erik Joelsson <erikj at openjdk.org> wrote:

>> Currently, if a user misuses a command, in some cases, SKARA CLI crashes and throws a stack trace, which is bad and does not provide useful information to the user. 
>> After investigating, I found that in many places, we don't check whether an option is followed by an argument, and it would trigger some issues.
>> In this patch, the program would always check the presence of an argument  before attempting to retrieve it for an option.
> cli/src/main/java/org/openjdk/skara/cli/GitSync.java line 345:
>> 343:                     branches.add(branch.trim());
>> 344:                 }
>> 345:             }
> What happened to this part?

Because we have a method GitSync#getOption in this method. The logic is as same as this.

    private String getOption(String name) throws IOException {
        var arg = ForgeUtils.getOption(name, arguments);
        if (arg != null) {
            return arg;
        var lines = repo.config("sync." + name);
        return lines.size() == 1 ? lines.get(0) : null;


PR Review Comment: https://git.openjdk.org/skara/pull/1502#discussion_r1167027778

More information about the skara-dev mailing list