Custom types on main parameters don't appear to work. (1.72)
See original GitHub issueMy reduced test case is as follows:
public class Main {
public static class CustomType {
private String something;
public CustomType(String something) {
this.something = something;
}
}
public static class CustomTypeConverter implements IStringConverter<CustomType> {
@Override
public CustomType convert(String value) {
return new CustomType(value);
}
}
@Parameters
public static class ExampleCommandArgs {
@Parameter(converter = CustomTypeConverter.class, required = true)
public CustomType mainArg;
}
public static void main(String[] args) {
JCommander.newBuilder()
.addObject(new ExampleCommandArgs())
.build()
.parse(args);
}
}
As far as I can see I’ve configured the converter properly, but the error I get is:
Exception in thread "main" com.beust.jcommander.ParameterException: Could not invoke null
Reason: Can not set Main$CustomType field Main$ExampleCommandArgs.mainArg to java.lang.String
at com.beust.jcommander.Parameterized.set(Parameterized.java:263)
at com.beust.jcommander.JCommander$MainParameter.addValue(JCommander.java:101)
at com.beust.jcommander.JCommander.parseValues(JCommander.java:773)
at com.beust.jcommander.JCommander.parse(JCommander.java:340)
at com.beust.jcommander.JCommander.parse(JCommander.java:319)
at Main.main(Main.java:38)
Note I get the same error on main arguments on commands as well.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:2
- Comments:7 (5 by maintainers)
Top Results From Across the Web
JCommander
For an alternative solution to parse a list of values, see Custom types - List value. 3.1.2. By factory. If the custom types...
Read more >Control settings in the Format Cells dialog box - Excel
To create a custom number format, click Custom in the Category list on the Number tab in the Format Cells dialog box. Then,...
Read more >Fix common formatting issues for custom parameters
Custom parameters can only contain letters, digits, and underscores. Custom parameters shouldn't begin with digits or include spaces.
Read more >12 User Defined Functions - A Sufficient Introduction to R
Chapter 12 User Defined Functions. It is very important to be able to define a piece of programing logic that is repeated often....
Read more >Lookups — stacker 1.7.2 documentation
If <lookup type> isn't provided, stacker will fall back to use the output lookup . ... ${output otherStack::IAMRole} Values: Env: Custom: ${custom ${output ......
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
Hi. I was about to post this same bug.
To be exact, custom types cannot be used in a main parameter, unless the main parameter is a list.
Here is an example that exhibits this problem:
The result is:
If I add
names
, or if I declare the parameter asList<Path>
instead ofPath
, this works properly.Since this is a dupe of #380 and #380 is done with #390 one should close this?