Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Boolean parameters flips on multiple parse

See original GitHub issue

I 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:closed
  • Created 6 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

sschuberthcommented, Apr 27, 2018

Just checking, @cbeust: Given (Kotlin) code like

@Parameter(description = "Enable debug logging and keep any temporary files.",
        names = ["--debug"])
private var debug = false

are you saying that specifying --debug --debug is intended to toggle debug to false again? I believe that behavior is very unintuitive. Because that’s the behavior we’re seeing with JCommander 1.74.

cbeustcommented, Mar 14, 2018

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.

Read more comments on GitHub >

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

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found