Hello Fuxiang,

thanks for your interest in Apache Commons Email.

I don't see a reason to add the add a null check here. We're talking about
a test class and we know that the VALID_EMAILS array will never be null.
Adding a null check just clutters the test code and makes it harder to
understand.

The reference you've provided is a completely different use case. Just
because somebody on StackOverflow implemented a tower defense game that
throws a NPE in a for loop doesn't mean all for loops in the world have to
be null checked :-)

If your looking for code quality metrics, you should have a look at tools
like FindBugs [1], PMD [2] and SonarQube [3] and the rules they implement.

Best regards and good luck with your studies,
Benedikt

[1] http://findbugs.sourceforge.net/
[2] http://pmd.sourceforge.net/
[3] http://www.sonarqube.org/


2014-07-21 0:32 GMT+02:00 Fuxiang Chen <[email protected]>:

> Dear Developers,
>
> We are a team of researchers from the Hong Kong University of Science and
> Technology (HKUST). Currently, we are studying how crowdsourcing can help
> developers to build a higher quality software.
>
> One of the subjects that we used is Apache Commons Email. From our
> experiment, we identified a few areas in a particular file "EmailTest.java"
> that might be proned to NullPointerException being thrown.
>
> The following 7 methods are identified as "NullPointerException Prone":
> 1) testAddToWithEncoding()
> 2) testAddTo2()
> 3) testAddCc2()
> 4) testAddBccWithEncoding()
> 5) testAddBcc2()
> 6) testAddReplyToWithEncoding()
> 7) testAddReplyTo2()
> All the above methods encompassed a for loop that checks for the length of
> the object
> "VALID_EMAILS" in its condition.
>
> Our reference from the Stack Overflow community pointed out that a null
> check to the object of a for loop is preferred to prevent the occurrence of
> NPE. The Stack Overflow reference to this is at "
> http://stackoverflow.com/questions/10565323";.
>
> We would like to propose an additional change for your kind consideration:
> 1) Having an extra assertion to check if the object "VALID_EMAILS" is null
>
> By having this new assertion, unnecessary NPE can be avoided.
>
> We hope that you can consider this and let us know about any thoughts. This
> will be a tremendous help to us in our continuing research to building a
> better software and to help the open-source community as a whole.
>
> Please do not hesitate to contact me @ [email protected] if there are any
> queries.
>
> Thanks a lot and have a great week ahead!
>
> --
> Warmest Regards,
>     Fuxiang
>



-- 
http://people.apache.org/~britter/
http://www.systemoutprintln.de/
http://twitter.com/BenediktRitter
http://github.com/britter

Reply via email to