Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IDefaultProvider for lists duplicates defaults for each name #457

Open
zentol opened this issue Sep 28, 2018 · 0 comments
Open

IDefaultProvider for lists duplicates defaults for each name #457

zentol opened this issue Sep 28, 2018 · 0 comments

Comments

@zentol
Copy link

zentol commented Sep 28, 2018

When using a list parameter with multiple names

        @Parameter(names = {"--label", "-l"},)
        List<String> labels;

and a IDefaultProvider

   public static final class ConstantDefaultProvider implements IDefaultProvider {
        @Override
        public String getDefaultValueFor(String optionName) {
            return "hello";
        }
    }

the labels parameter will contain the default for each name, in this case twice, once parsing is complete.

The reason is that separate a ParameterDescription is created for each name of a parameter, which are however backed by single Parameter object. The default provider is called once for each description, which is acceptable for single value fields since the field will be simply overwritten (provided that the default provider handles both cases the same way), but in the case of collections we are mutating the field instead causing duplicates.

npetzall added a commit to npetzall/schemaspy that referenced this issue Mar 24, 2023
* Bug in jcommander loads same default for each option name/alias
  cbeust/jcommander#457
npetzall added a commit to npetzall/schemaspy that referenced this issue Mar 24, 2023
* Bug in jcommander loads same default for each option name/alias
  cbeust/jcommander#457

fixes schemaspy#1103
npetzall added a commit to schemaspy/schemaspy that referenced this issue Mar 24, 2023
* Bug in jcommander loads same default for each option name/alias
  cbeust/jcommander#457

fixes #1103
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant