Skip to content

Address NullAway warnings and refine StepVerifier nullability#4126

Merged
chemicL merged 21 commits intomainfrom
remaining-nullability-handling
Oct 31, 2025
Merged

Address NullAway warnings and refine StepVerifier nullability#4126
chemicL merged 21 commits intomainfrom
remaining-nullability-handling

Conversation

@chemicL
Copy link
Member

@chemicL chemicL commented Oct 31, 2025

This PR addresses the remaining NullAway warnings left after #4091.

It also contains public API refinenements around StepVerifier and TestPublisher from reactor-test to allow verifying non-compliant Publishers against null values.

Follow-up on #878

Signed-off-by: Dariusz Jędrzejczyk <dariusz.jedrzejczyk@broadcom.com>
Signed-off-by: Dariusz Jędrzejczyk <dariusz.jedrzejczyk@broadcom.com>
Signed-off-by: Dariusz Jędrzejczyk <dariusz.jedrzejczyk@broadcom.com>
Signed-off-by: Dariusz Jędrzejczyk <dariusz.jedrzejczyk@broadcom.com>
Signed-off-by: Dariusz Jędrzejczyk <dariusz.jedrzejczyk@broadcom.com>
Signed-off-by: Dariusz Jędrzejczyk <dariusz.jedrzejczyk@broadcom.com>
Signed-off-by: Dariusz Jędrzejczyk <dariusz.jedrzejczyk@broadcom.com>
…l actual

Signed-off-by: Dariusz Jędrzejczyk <dariusz.jedrzejczyk@broadcom.com>
Signed-off-by: Dariusz Jędrzejczyk <dariusz.jedrzejczyk@broadcom.com>
Signed-off-by: Dariusz Jędrzejczyk <dariusz.jedrzejczyk@broadcom.com>
Signed-off-by: Dariusz Jędrzejczyk <dariusz.jedrzejczyk@broadcom.com>
Signed-off-by: Dariusz Jędrzejczyk <dariusz.jedrzejczyk@broadcom.com>
Signed-off-by: Dariusz Jędrzejczyk <dariusz.jedrzejczyk@broadcom.com>
Signed-off-by: Dariusz Jędrzejczyk <dariusz.jedrzejczyk@broadcom.com>
Signed-off-by: Dariusz Jędrzejczyk <dariusz.jedrzejczyk@broadcom.com>
Signed-off-by: Dariusz Jędrzejczyk <dariusz.jedrzejczyk@broadcom.com>
Signed-off-by: Dariusz Jędrzejczyk <dariusz.jedrzejczyk@broadcom.com>
Signed-off-by: Dariusz Jędrzejczyk <dariusz.jedrzejczyk@broadcom.com>
Signed-off-by: Dariusz Jędrzejczyk <dariusz.jedrzejczyk@broadcom.com>
Signed-off-by: Dariusz Jędrzejczyk <dariusz.jedrzejczyk@broadcom.com>
Signed-off-by: Dariusz Jędrzejczyk <dariusz.jedrzejczyk@broadcom.com>
@chemicL chemicL added this to the 3.8.0 milestone Oct 31, 2025
@chemicL chemicL requested a review from a team as a code owner October 31, 2025 13:23
@chemicL chemicL added type/enhancement A general enhancement warn/api-change Breaking change with compilation errors labels Oct 31, 2025
return;
}
queue.offer(buffers.remove(idx));
queue.offer(bufs.remove(idx));

Check notice

Code scanning / CodeQL

Ignored error status of call Note

Method close ignores exceptional return value of Queue.offer.
break;
}

assert next != null && next.value != null : "next and next.value must not be null";

Check warning

Code scanning / CodeQL

Useless null check Warning

This check is useless.
next
cannot be null at this check, since it is guarded by
... == ...
.

Copilot Autofix

AI 4 months ago

To fix the problem, the unnecessary redundancy in the assertion at line 241 should be eliminated. Specifically, the check for next != null is not needed as the control flow guarantees next is never null at this point. The best way to fix this without changing existing functionality is:

  • In reactor-core/src/main/java/reactor/core/publisher/FluxReplay.java at line 241, change assert next != null && next.value != null : "next and next.value must not be null"; to assert next.value != null : "next.value must not be null";
  • No additional imports or method changes are required.
Suggested changeset 1
reactor-core/src/main/java/reactor/core/publisher/FluxReplay.java

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/reactor-core/src/main/java/reactor/core/publisher/FluxReplay.java b/reactor-core/src/main/java/reactor/core/publisher/FluxReplay.java
--- a/reactor-core/src/main/java/reactor/core/publisher/FluxReplay.java
+++ b/reactor-core/src/main/java/reactor/core/publisher/FluxReplay.java
@@ -238,7 +238,7 @@
 						break;
 					}
 
-					assert next != null && next.value != null : "next and next.value must not be null";
+					assert next.value != null : "next.value must not be null";
 					a.onNext(next.value);
 
 					e++;
EOF
@@ -238,7 +238,7 @@
break;
}

assert next != null && next.value != null : "next and next.value must not be null";
assert next.value != null : "next.value must not be null";
a.onNext(next.value);

e++;
Copilot is powered by AI and may make mistakes. Always verify output.
break;
}

assert next != null && next.value != null : "next and next.value must not be null";

Check warning

Code scanning / CodeQL

Useless null check Warning

This check is useless.
next
cannot be null at this check, since it is guarded by
... == ...
.

Copilot Autofix

AI 4 months ago

To fix the problem, remove the useless check for next != null in the assertion at line 882. Since the empty case was already handled, the assertion only needs to check that next.value != null. No new methods, imports, or definitions are needed. Only alter the relevant assertion in reactor-core/src/main/java/reactor/core/publisher/FluxReplay.java.

Suggested changeset 1
reactor-core/src/main/java/reactor/core/publisher/FluxReplay.java

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/reactor-core/src/main/java/reactor/core/publisher/FluxReplay.java b/reactor-core/src/main/java/reactor/core/publisher/FluxReplay.java
--- a/reactor-core/src/main/java/reactor/core/publisher/FluxReplay.java
+++ b/reactor-core/src/main/java/reactor/core/publisher/FluxReplay.java
@@ -879,7 +879,7 @@
 						break;
 					}
 
-					assert next != null && next.value != null : "next and next.value must not be null";
+					assert next.value != null : "next.value must not be null";
 					a.onNext(next.value);
 
 					e++;
EOF
@@ -879,7 +879,7 @@
break;
}

assert next != null && next.value != null : "next and next.value must not be null";
assert next.value != null : "next.value must not be null";
a.onNext(next.value);

e++;
Copilot is powered by AI and may make mistakes. Always verify output.
}

// NullAway issue?
assert si != null : "si can not be null here";

Check warning

Code scanning / CodeQL

Useless null check Warning

This check is useless.
si
cannot be null at this check, since it is guarded by
... != ...
.

Copilot Autofix

AI 4 months ago

The best fix is to remove the redundant assertion statement on line 169: assert si != null : "si can not be null here";. This will clean up the code, improve readability, and avoid confusion or misleading logic. All other functionality is preserved. No other definitions or imports are needed.

Make this change only in reactor-core/src/main/java/reactor/core/publisher/FluxSwitchMapNoPrefetch.java.

Suggested changeset 1
reactor-core/src/main/java/reactor/core/publisher/FluxSwitchMapNoPrefetch.java

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/reactor-core/src/main/java/reactor/core/publisher/FluxSwitchMapNoPrefetch.java b/reactor-core/src/main/java/reactor/core/publisher/FluxSwitchMapNoPrefetch.java
--- a/reactor-core/src/main/java/reactor/core/publisher/FluxSwitchMapNoPrefetch.java
+++ b/reactor-core/src/main/java/reactor/core/publisher/FluxSwitchMapNoPrefetch.java
@@ -166,7 +166,6 @@
 			}
 
 			// NullAway issue?
-			assert si != null : "si can not be null here";
 			final int nextIndex = si.index + 1;
 			final SwitchMapInner<T, R> nsi = new SwitchMapInner<>(this, this.actual, nextIndex, this.logger);
 
EOF
@@ -166,7 +166,6 @@
}

// NullAway issue?
assert si != null : "si can not be null here";
final int nextIndex = si.index + 1;
final SwitchMapInner<T, R> nsi = new SwitchMapInner<>(this, this.actual, nextIndex, this.logger);

Copilot is powered by AI and may make mistakes. Always verify output.
FluxPublish.PubSubInner<T>[] a = subscribers;

if (a != EMPTY && !empty) {
assert q != null : "q can not be null when !empty";

Check warning

Code scanning / CodeQL

Useless null check Warning

This check is useless.
q
cannot be null at this check, since it is guarded by
... == ...
.

Copilot Autofix

AI 4 months ago

To fix the problem, remove the unnecessary assertion assert q != null : "q can not be null when !empty"; on line 410. This will clean up the code by eliminating misleading checks, reducing clutter, and making intent clearer, as the previous guard ensures this case is impossible.

No imports or other definitions are needed for this edit. Only the code in the vicinity of line 410, in the drain() method of reactor-core/src/main/java/reactor/core/publisher/SinkManyEmitterProcessor.java, needs to be changed.


Suggested changeset 1
reactor-core/src/main/java/reactor/core/publisher/SinkManyEmitterProcessor.java

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/reactor-core/src/main/java/reactor/core/publisher/SinkManyEmitterProcessor.java b/reactor-core/src/main/java/reactor/core/publisher/SinkManyEmitterProcessor.java
--- a/reactor-core/src/main/java/reactor/core/publisher/SinkManyEmitterProcessor.java
+++ b/reactor-core/src/main/java/reactor/core/publisher/SinkManyEmitterProcessor.java
@@ -407,7 +407,6 @@
 			FluxPublish.PubSubInner<T>[] a = subscribers;
 
 			if (a != EMPTY && !empty) {
-				assert q != null : "q can not be null when !empty";
 				long maxRequested = Long.MAX_VALUE;
 
 				int len = a.length;
EOF
@@ -407,7 +407,6 @@
FluxPublish.PubSubInner<T>[] a = subscribers;

if (a != EMPTY && !empty) {
assert q != null : "q can not be null when !empty";
long maxRequested = Long.MAX_VALUE;

int len = a.length;
Copilot is powered by AI and may make mistakes. Always verify output.
@chemicL chemicL merged commit 03521d9 into main Oct 31, 2025
11 checks passed
@chemicL chemicL deleted the remaining-nullability-handling branch October 31, 2025 17:03
@chemicL chemicL removed the warn/api-change Breaking change with compilation errors label Oct 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type/enhancement A general enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant