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


##########
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:
   Went with the null-tolerant reading here. Util.isEmpty is the guard this 
package already uses for name checks, and returning an empty list for null 
lines up with the contract (no match means empty list) rather than leaking an 
NPE from startsWith. I made that explicit in the Javadoc and added a null case 
to the test.



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