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

If bean is null, message "X is not a valid option" occurs #158

Open
ghost opened this issue Apr 9, 2018 · 0 comments
Open

If bean is null, message "X is not a valid option" occurs #158

ghost opened this issue Apr 9, 2018 · 0 comments

Comments

@ghost
Copy link

ghost commented Apr 9, 2018

Consider this:

public static Bean bean;

public static void main(String[] args) throws IOException, CmdLineException {
	CmdLineParser parser = new CmdLineParser(bean);
	parser.parseArgument(args);

	Appendable output;
	if (bean.getOutputFile() == null) {
		output = new ConsoleAppendable();
	} else {
		output = new BufferedWriter(new FileWriter(bean.getOutputFile()));
	}
}

with Bean being:

@Getter
@Setter
@ToString
public class Bean {
	@Option(name = "-o", required = false)
	private File outputFile;
}

will result in:

Exception in thread "main" org.kohsuke.args4j.CmdLineException: "-o=foo.txt" is not a valid option
	at org.kohsuke.args4j.CmdLineParser.parseArgument(CmdLineParser.java:497)
	at com.pany.project.Main.main(Main.java:24)

because bean is null.

Proposal

  1. Fix javadoc (javadoc is stating "processing will be skipped o null input", what is not the case)
    and/or
  2. Check for null input and print a correct error message
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

0 participants