Skip to content

Commit 6c2fad8

Browse files
SONARJAVA-5502 Jot down first notes
1 parent 6902708 commit 6c2fad8

File tree

2 files changed

+36
-12
lines changed

2 files changed

+36
-12
lines changed

rules/S7480/java/metadata.json

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
2-
"title": "FIXME",
2+
"title": "The result of \"Downstream.push\" should not be ignored",
33
"type": "CODE_SMELL",
44
"status": "ready",
55
"remediation": {
66
"func": "Constant\/Issue",
7-
"constantCost": "5min"
7+
"constantCost": "15min"
88
},
99
"tags": [
1010
],
@@ -13,13 +13,12 @@
1313
"sqKey": "S7480",
1414
"scope": "All",
1515
"defaultQualityProfiles": ["Sonar way"],
16-
"quickfix": "unknown",
16+
"quickfix": "infeasible",
1717
"code": {
1818
"impacts": {
19-
"MAINTAINABILITY": "HIGH",
20-
"RELIABILITY": "MEDIUM",
21-
"SECURITY": "LOW"
19+
"MAINTAINABILITY": "LOW",
20+
"RELIABILITY": "MEDIUM"
2221
},
23-
"attribute": "CONVENTIONAL"
22+
"attribute": "LOGICAL"
2423
}
2524
}

rules/S7480/java/rule.adoc

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
FIXME: add a description
1+
The integrator function can pass data downstream using the push method
2+
In return, the stream should return a result indicating whether it accepted the latest value.
23

3-
// If you want to factorize the description uncomment the following line and create the file.
4-
//include::../description.adoc[]
4+
Ignoring the value returned by `Downstream.push` might lead to inconsistent behavior of the integrator.
55

66
== Why is this an issue?
77

@@ -18,14 +18,39 @@ FIXME: remove the unused optional headers (that are commented out)
1818

1919
[source,java,diff-id=1,diff-type=noncompliant]
2020
----
21-
FIXME
21+
Gatherer.ofSequential(
22+
() -> new AtomicInteger(100),
23+
(state, element, downstream) -> {
24+
int newState = state.addAndGet(element);
25+
downstream.push(newState); // Noncompliant: ignoring return value
26+
return true;
27+
});
2228
----
2329

2430
==== Compliant solution
2531

2632
[source,java,diff-id=1,diff-type=compliant]
2733
----
28-
FIXME
34+
Gatherer.ofSequential(
35+
() -> new AtomicInteger(100),
36+
(state, element, downstream) -> {
37+
int newState = state.addAndGet(element);
38+
return downstream.push(newState); // Compliant
39+
});
40+
----
41+
42+
[source,java,diff-id=1,diff-type=compliant]
43+
----
44+
Gatherer.ofSequential(
45+
() -> new AtomicInteger(100),
46+
(state, element, downstream) -> {
47+
int newState = state.addAndGet(element);
48+
if (downstream.push(newState)) {
49+
// Do something to handle this specific case
50+
return false;
51+
}
52+
return true;
53+
});
2954
----
3055

3156
//=== How does this work?

0 commit comments

Comments
 (0)