[
https://issues.apache.org/jira/browse/CLI-170?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12635219#action_12635219
]
J. Lewis Muir commented on CLI-170:
-----------------------------------
Changing the Maven POM will only solve the problem in a superficial way, and
only when the test cases are run using Maven. I use Eclipse and its built-in
JUnit support to run the test cases. In this case, and very likely in the case
of other IDEs, the POM file is not used, so the error messages will continue to
be written to stderr whenever the unit tests are run.
If you think the information provided by the messages to stderr are useful, I
suggest changing the methods to throw exceptions for these error cases. But if
you don't like that, I'd say the next best thing would be to write the messages
to some logging framework so there's good control over what messages get
written where. In this case, I think the default should be that the messages
are not written, and the developer would need to explicitly turn them on.
I don't think a library should ever write error messages to stderr on its own;
that's poor design. When I use a library in software I write, I expect the
library to never write to stdout nor stderr unless I have told it to (e.g. a
logging framework library or a function specifically for writing to those
streams). I want to have complete control over what gets written to stdout and
stderr.
> TypeHandler prints messages to stderr
> -------------------------------------
>
> Key: CLI-170
> URL: https://issues.apache.org/jira/browse/CLI-170
> Project: Commons CLI
> Issue Type: Bug
> Components: Validation
> Affects Versions: 1.2
> Reporter: J. Lewis Muir
> Fix For: 1.2
>
> Attachments: remove-messages-to-stderr.patch
>
> Original Estimate: 0.5h
> Remaining Estimate: 0.5h
>
> Certain methods in {{TypeHandler}} print a message to stderr when they are
> unable to create the object they are to return. I don't think this should
> be. The documentation for each method clearly states that if it is unable to
> create the object, it returns {{null}}. If more information should be
> reported to the caller, these methods should be changed to throw an
> exception. I've removed the printing of these messages from {{TypeHandler}}.
> This fix also makes the unit test output clean. Right now, certain test
> cases exercise the "returns {{null}}" behavior of some of the {{TypeHandler}}
> methods, and this causes various error messages to be written to stderr which
> makes the test case output look unclean and like something has gone wrong
> when in fact everything is working correctly.
> Attached is a patch for this fix. The patch is against
> [http://svn.apache.org/repos/asf/commons/proper/cli/branches/cli-1.x].
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.