Last active
March 17, 2016 04:31
-
-
Save emopers/b8045e701d2117e1a1f3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
##Improvement in property## | |
Iterator_hasNext property (https://goo.gl/sO43It) requires a program to guarantee that to call Iterator.hasNext() | |
before calling Iterator.next() in order to prevent the NullPointerException triggered when there is no next element in | |
the underlying collection without proper debugging information. From our inspection of the monitoring | |
on 200 open source projects with this property, we found that most false alarms of this property was | |
triggered because the developer check the validity of calling Iterator.next() by means beside calling Iterator.hasNext(), | |
typically by calling collection.isEmpty() or collection.size(). We hereby suggest adding such checks as valid | |
prerequisites for calling Iterator.next() to avoid false alarms. | |
For example, in compile-testing | |
https://github.com/google/compile-testing/blob/51cdab8998ea25210e8d3726982947054f421f94/src/main/java/com/google/testing/compile/TypeEnumerator.java#L102 | |
Iterator_HasNext is violated while the validity of this call is checked by collection.isEmpty(). | |
We have seen many similar kind of false alarms in the 200 open source projects we monitored with JavaMOP. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment