JCommander#parseValues throws NullPointerException (since 1.71)
See original GitHub issueDuring the changes in commit 4435722a0b45be660b1b58834d4f5326fc78c9ad new defect has crept in which raises a NullPointerException.
Exception in thread "main" java.lang.NullPointerException
at com.beust.jcommander.JCommander.parseValues(JCommander.java:718)
at com.beust.jcommander.JCommander.parse(JCommander.java:340)
at com.beust.jcommander.JCommander.parseWithoutValidation(JCommander.java:330)
The Boolean in line 717 Boolean value = (Boolean) pd.getParameterized().get(pd.getObject());
can be null if no default value is present for a Boolean parameter like:
@Parameter(names = {"--flag"}, description = "Just a simple flag")
private Boolean simpleFlag;
This behaviour is not obvious because strings can be null. And a nullable parameter is important if one just wants to override a configured value with those of the command line if they are present.
Issue Analytics
- State:
- Created 6 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
How to Fix and Avoid NullPointerException in Java - Rollbar
NullPointerException in Java occurs when a variable is accessed which is not pointing to any object and refers to nothing or null.
Read more >java - What is a NullPointerException, and how do I fix it?
Obviously, it can't do this, so it throws a null pointer exception . In general, it's because something hasn't been initialized properly. Share....
Read more >Java NullPointerException - Detect, Fix, and Best Practices
When we run the above program, it throws the following NullPointerException error message. Exception in thread "main" java.lang.
Read more >NullPointerException (Java Platform SE 7 ) - Oracle Help Center
Thrown when an application attempts to use null in a case where an object is required. These include: Calling the instance method of...
Read more >How to resolve the java.lang.NullPointerException - Educative.io
In Java, the java.lang.NullPointerException is thrown when a reference variable is accessed (or de-referenced) and is not pointing to any object.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@cbeust The problem is still there using version from maven central. I don’t know how to publish a new version to central and perhaps it is a task that fall on you being main maintainer 😃 (beside if I use
./kobaltw clean compîle publishToMavenLocal
on WIndows, it fails withjava.lang.IllegalArgumentException: Illegal character in opaque part at index 11: jar:file:E:\git\github\jcommander\.\kobaltBuild\
=> you might need to use Path.toURI() or File.toURI() …) Nonetheless, my fix fix your problem @bisoldi .Unfortunately, it does not work for me. Using v1.72, I still get a NullPointerException, however as soon as I switched the dependency to v1.69, it worked fine. Below is the test class I used.
Here is the full stack trace: