Skip to content

Commit ca6ff1c

Browse files
Add some context to the rule
1 parent c4e938e commit ca6ff1c

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

rules/S7480/java/metadata.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"title": "The result of \"Downstream.push\" should not be ignored",
3-
"type": "CODE_SMELL",
3+
"type": "BUG",
44
"status": "ready",
55
"remediation": {
66
"func": "Constant\/Issue",

rules/S7480/java/rule.adoc

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ The integrator function of stream gatherers can pass data downstream using the p
44
The down stream should return a result indicating whether it accepted the latest value.
55

66
Ignoring the value returned by `Downstream.push` might lead to inconsistent behavior of the integrator.
7+
Indeed, if `downstream.push` returns `false`, and no longer accepts elements, the decision to continue processing the incoming stream should be deliberate.
78

89
== How to fix it
910
Use or return the result of `Downstream.push`.
@@ -42,13 +43,23 @@ Gatherer.ofSequential(
4243
(state, element, downstream) -> {
4344
int newState = state.addAndGet(element);
4445
if (!downstream.push(newState)) {
45-
// Do something to recover from rejected push
46+
// Since the downstream is no longer accepting elements, we stop processing incoming streams
4647
return false;
4748
}
4849
return true;
4950
});
5051
----
5152

53+
[source,java,diff-id=1,diff-type=compliant]
54+
----
55+
Gatherer.ofSequential(
56+
() -> new AtomicInteger(100),
57+
(state, element, downstream) -> {
58+
int newState = state.addAndGet(element);
59+
return handleResult(downstream.push(newState));
60+
});
61+
----
62+
5263
//=== How does this work?
5364

5465
//=== Pitfalls

0 commit comments

Comments
 (0)