Boolean parameters flips on multiple parse
See original GitHub issueI looked in the documentation to see if this is intended, but I don’t think it is. I recently upgraded from version 1.48 to 1.72 and noticed that boolean parameters would now toggle between true and false when parsed multiple times.
public class Parameters
{
@Parameter(names = {"-f" }, description = "flag" )
private boolean flagged = false;
}
public void parameterTest()
{
Parameters parameters = new Parameters();
JCommander jCommander = new JCommander( parameters );
jCommander.parse( "-f" );
Assert.assertTrue( parameters.flagged );
jCommander.parse( "-f" );
Assert.assertTrue( parameters.flagged ); //this fails
}
Issue Analytics
- State:
- Created 6 years ago
- Comments:9 (4 by maintainers)
Top Results From Across the Web
Java - Working with multiple Boolean attributes as flags
It is a compact representation of a sequence of boolean values, ... or flip them (i.e., reverse the value) with: flags.flip(FLAG1);.
Read more >Flipping a Boolean When All Values Meet a Condition with LINQ
Here's a quick example: you want to loop through a collection and flip a boolean if a condition is met by all of...
Read more >2 Ways to Convert Values to Boolean in JavaScript
The first ! coerce the value to a boolean and inverse it. In this case, !value will return false . So to reverse...
Read more >Invert boolean | PyCharm Documentation - JetBrains
This refactoring aims to flip the value of a Boolean variable and all its usages from True to False and vice versa.
Read more >Boolean Algebra — Python EDA Documentation - PyEDA
Now divide all of time into two periods: 1) before the flip, and 2) after the ... Let's create a few Boolean expression...
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
Just checking, @cbeust: Given (Kotlin) code like
are you saying that specifying
--debug --debug
is intended to toggle debug tofalse
again? I believe that behavior is very unintuitive. Because that’s the behavior we’re seeing with JCommander 1.74.That’s expected: boolean parameters have by definition an arity of zero: you only need to pass
-v
to flip it. Any additional parameter will be interpreted further.If you want to support
-v true
, you need to set its arity to one.