Compare commits
1 Commits
master
...
jb/s2272-k
Author | SHA1 | Date | |
---|---|---|---|
![]() |
8dcacc2717 |
@ -1,28 +1,2 @@
|
|||||||
{
|
{
|
||||||
"title": "\"Iterator.next()\" methods should throw \"NoSuchElementException\"",
|
|
||||||
"type": "BUG",
|
|
||||||
"status": "ready",
|
|
||||||
"remediation": {
|
|
||||||
"func": "Constant\/Issue",
|
|
||||||
"constantCost": "5min"
|
|
||||||
},
|
|
||||||
"tags": [
|
|
||||||
"error-handling",
|
|
||||||
"unpredictable"
|
|
||||||
],
|
|
||||||
"extra": {
|
|
||||||
"coveredLanguages": [
|
|
||||||
"Java"
|
|
||||||
],
|
|
||||||
"replacementRules": [
|
|
||||||
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"defaultSeverity": "Minor",
|
|
||||||
"ruleSpecification": "RSPEC-2272",
|
|
||||||
"sqKey": "S2272",
|
|
||||||
"scope": "Main",
|
|
||||||
"defaultQualityProfiles": [
|
|
||||||
"Sonar way"
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
|
2
rules/S2272/kotlin/metadata.json
Normal file
2
rules/S2272/kotlin/metadata.json
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
{
|
||||||
|
}
|
32
rules/S2272/kotlin/rule.adoc
Normal file
32
rules/S2272/kotlin/rule.adoc
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
By contract, any implementation of the `kotlin.collections.Iterator.next()` method should throw a `kotlin.NoSuchElementException` when the iteration has no more elements. Any other behavior when the iteration is done could lead to unexpected behavior for users of this `Iterator`.
|
||||||
|
|
||||||
|
|
||||||
|
== Noncompliant Code Example
|
||||||
|
|
||||||
|
----
|
||||||
|
class MyIterator : Iterator<String?> {
|
||||||
|
// ...
|
||||||
|
override fun next(): String? {
|
||||||
|
if(!hasNext()){
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
// ...
|
||||||
|
}
|
||||||
|
}
|
||||||
|
----
|
||||||
|
|
||||||
|
|
||||||
|
== Compliant Solution
|
||||||
|
|
||||||
|
----
|
||||||
|
class MyIterator : Iterator<String?> {
|
||||||
|
// ...
|
||||||
|
override fun next(): String? {
|
||||||
|
if(!hasNext()){
|
||||||
|
throw NoSuchElementException()
|
||||||
|
}
|
||||||
|
// ...
|
||||||
|
}
|
||||||
|
}
|
||||||
|
----
|
||||||
|
|
@ -1,2 +1,29 @@
|
|||||||
{
|
{
|
||||||
|
"title": "\"Iterator.next()\" methods should throw \"NoSuchElementException\"",
|
||||||
|
"type": "BUG",
|
||||||
|
"status": "ready",
|
||||||
|
"remediation": {
|
||||||
|
"func": "Constant\/Issue",
|
||||||
|
"constantCost": "5min"
|
||||||
|
},
|
||||||
|
"tags": [
|
||||||
|
"error-handling",
|
||||||
|
"unpredictable"
|
||||||
|
],
|
||||||
|
"extra": {
|
||||||
|
"coveredLanguages": [
|
||||||
|
"Java",
|
||||||
|
"Kotlin"
|
||||||
|
],
|
||||||
|
"replacementRules": [
|
||||||
|
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"defaultSeverity": "Minor",
|
||||||
|
"ruleSpecification": "RSPEC-2272",
|
||||||
|
"sqKey": "S2272",
|
||||||
|
"scope": "Main",
|
||||||
|
"defaultQualityProfiles": [
|
||||||
|
"Sonar way"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user