Skip to content

Commit 81cf673

Browse files
committed
Fix NPE in DefaultParser.isLongOption(String) seen in the wild.
1 parent 3d90d5d commit 81cf673

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

src/changes/changes.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,14 @@
2323
<body>
2424

2525
<release version="1.5" date="tba" description="tba">
26+
<!-- FIX -->
27+
<action type="update" dev="ggregory" due-to="Gary Gregory">
28+
Fix NPE in DefaultParser.isLongOption(String).
29+
</action>
2630
<action type="update" dev="britter" due-to="Krishna Mohan Rao Kandunoori" issue="CLI-279">
2731
@param or @return lines should end with a period in CommandLine.java
2832
</action>
33+
<!-- ADD -->
2934
<action type="add" dev="chtompki" due-to="Rubin Simons" issue="CLI-217">
3035
Accommodate toggling partial matching in DefaultParser.
3136
</action>
@@ -41,6 +46,7 @@
4146
<action type="add" dev="ggregory" due-to="Alex Nordlund" issue="CLI-282">
4247
TypeHandler should throw ParseException for an unsupported class.
4348
</action>
49+
<!-- UPDATE -->
4450
<action type="update" dev="ggregory" issue="CLI-294">
4551
Update Java from version 5 to 7.
4652
</action>

src/main/java/org/apache/commons/cli/DefaultParser.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ private boolean isOption(final String token)
347347
private boolean isShortOption(final String token)
348348
{
349349
// short options (-S, -SV, -S=V, -SV1=V2, -S1S2)
350-
if (!token.startsWith("-") || token.length() == 1)
350+
if (token == null || !token.startsWith("-") || token.length() == 1)
351351
{
352352
return false;
353353
}
@@ -370,7 +370,7 @@ private boolean isShortOption(final String token)
370370
*/
371371
private boolean isLongOption(final String token)
372372
{
373-
if (!token.startsWith("-") || token.length() == 1)
373+
if (token == null || !token.startsWith("-") || token.length() == 1)
374374
{
375375
return false;
376376
}

0 commit comments

Comments
 (0)