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

Validate for collections #6

Open
valery1707 opened this issue Oct 15, 2018 · 0 comments
Open

Validate for collections #6

valery1707 opened this issue Oct 15, 2018 · 0 comments
Assignees
Labels

Comments

@valery1707
Copy link
Owner

This arguments description:

public class Args {
    @Parameter(
        names = {"-a", "--app", "--root"},
        validateValueWith = ExistsDirectoryReadable.class
    )
    private List<File> application = Arrays.asList(
            new File("/srv/"),
            new File("/")
    );
}

will block parsing argument values with exception:

Exception in thread "main" java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:606)
        at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48)
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:87)
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:50)
        at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51)
Caused by: java.lang.ClassCastException: java.util.Arrays$ArrayList cannot be cast to java.io.File
        at name.valery1707.jcommander.validators.io.ExistsDirectoryReadable.check(ExistsDirectoryReadable.java:7)
        at name.valery1707.jcommander.validators.ValueChecker.check(ValueChecker.java:18)
        at name.valery1707.jcommander.validators.ValueChecker.validate(ValueChecker.java:11)
        at com.beust.jcommander.ParameterDescription.validateValueParameter(ParameterDescription.java:285)
        at com.beust.jcommander.ParameterDescription.validateValueParameter(ParameterDescription.java:275)
        at com.beust.jcommander.ParameterDescription.validateDefaultValues(ParameterDescription.java:165)
        at com.beust.jcommander.ParameterDescription.init(ParameterDescription.java:158)
        at com.beust.jcommander.ParameterDescription.<init>(ParameterDescription.java:73)
        at com.beust.jcommander.JCommander.addDescription(JCommander.java:550)
        at com.beust.jcommander.JCommander.createDescriptions(JCommander.java:522)
        at com.beust.jcommander.JCommander.parse(JCommander.java:280)
        at com.beust.jcommander.JCommander.parse(JCommander.java:265)
        ... 9 more

Tested with jcommander:1.48 and jcommander-validator-io:0.1.11 under spring-boot:1.5.16.RELEASE

@valery1707 valery1707 self-assigned this Oct 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant