Copilot commented on code in PR #434:
URL: https://github.com/apache/commons-cli/pull/434#discussion_r3637989913


##########
src/main/java/org/apache/commons/cli/Options.java:
##########
@@ -219,6 +219,10 @@ public Options addRequiredOption(final String opt, final 
String longOpt, final b
     public List<String> getMatchingOptions(final String opt) {
         final String clean = Util.stripLeadingHyphens(opt);
         final List<String> matchingOpts = new ArrayList<>();
+        // an empty name is not a partial name, it would match every long 
option
+        if (Util.isEmpty(clean)) {
+            return matchingOpts;
+        }

Review Comment:
   The new `Util.isEmpty(clean)` guard also treats `null` as empty, which 
changes `getMatchingOptions(null)` from throwing a `NullPointerException` (via 
`startsWith(null)`) to returning an empty list. If this method is intended to 
remain fail-fast for programmer errors (and this PR is only about rejecting 
empty names like "--"), consider restricting this check to the empty string 
only (or alternatively document/test the new null-tolerant behavior explicitly).



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to