You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Using version 1.72, an NPE is thrown when using a field of type Boolean without initializing it.
This was working normally until version 1.60.
I have not checked against other versions
Test case
Here's a simple test case that should otherwise work:
import com.beust.jcommander.JCommander;
import com.beust.jcommander.Parameter;
import org.junit.Test;
import static org.junit.Assert.assertTrue;
public class TestNPE {
public static final String PARAM_NAME = "--refresh"; //NOI18N
@Test
public void testBooleanWithoutDefaultValue() {
CmdArgs args = new CmdArgs();
JCommander commander = new JCommander(args);
commander.setAcceptUnknownOptions(true);
commander.parse(PARAM_NAME);
assertTrue(args.m_refresh);
}
public static class CmdArgs {
@Parameter(names = PARAM_NAME)
private Boolean m_refresh;
}
}
but fails with the following exception:
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.parse(JCommander.java:319)
at TestNPE.testBooleanWithoutDefaultValue(TestNPE.java:20)
...
Workarounds:
Initialize field to false
Switch to using boolean instead
The text was updated successfully, but these errors were encountered:
Using version 1.72, an NPE is thrown when using a field of type Boolean without initializing it.
This was working normally until version 1.60.
I have not checked against other versions
Test case
Here's a simple test case that should otherwise work:
but fails with the following exception:
Workarounds:
The text was updated successfully, but these errors were encountered: