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

Fix potential bug in Env default value provider #644

Merged
merged 9 commits into from
Apr 7, 2020
Merged

Fix potential bug in Env default value provider #644

merged 9 commits into from
Apr 7, 2020

Conversation

usmansaleem
Copy link
Member

Bypass default value from environment variable provider for positional parameter. In case of subcommands such as help this could have thrown class cast exception

Signed-off-by: Usman Saleem usman@usmans.info

 -- Bypass default value for positional parameter. In case of subcommands such as help this could have thrown class cast exception

Signed-off-by: Usman Saleem <usman@usmans.info>
Copy link
Contributor

@CjHare CjHare left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about a test case covering the control flow / highlighting the bug?

Signed-off-by: Usman Saleem <usman@usmans.info>
Signed-off-by: Usman Saleem <usman@usmans.info>
Signed-off-by: Usman Saleem <usman@usmans.info>
@@ -36,6 +36,10 @@ public EnvironmentVariableDefaultProvider(final Map<String, String> environment)

@Override
public String defaultValue(final ArgSpec argSpec) {
if (!argSpec.isOption()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the reasoning for using the negation of isOption() instead of simply using isPositional() to identify a positional param?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fair point ... I think I saw an example which was using isOption which stuck in my head, i didn't realised about isPositional. I'll change it to use isPositional. 👍

Signed-off-by: Usman Saleem <usman@usmans.info>
@usmansaleem usmansaleem merged commit 1403d3e into hyperledger:master Apr 7, 2020
@usmansaleem usmansaleem deleted the env_provider_bug branch April 7, 2020 01:30
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

Successfully merging this pull request may close these issues.

2 participants