Fixed
Pinned fields
Click on the next to a field label to start pinning.
Details
Assignee
Marco KaufmannMarco KaufmannReporter
Marco KaufmannMarco KaufmannStart date
Sep 18, 2024Components
Fix versions
Due date
Sep 24, 2024Priority
Normal
Details
Details
Assignee
Marco Kaufmann
Marco KaufmannReporter
Marco Kaufmann
Marco KaufmannStart date
Sep 18, 2024
Components
Fix versions
Due date
Sep 24, 2024
Priority

Sentry
Sentry
Sentry
Created August 5, 2024 at 12:17 PM
Updated October 16, 2024 at 2:06 PM
Resolved September 24, 2024 at 2:44 PM
S1764 raises an issue if the left and right argument of a binary operator are identical expressions. This, however, is an issue for referential transparent expressions only, i.e., expressions whose value does not change and that have no side effects.
The current rule implementation does not take this into account and consequently, reports on the following code example:
public interface HelloWorld { default boolean hello() { Random r = new Random(); return r.nextBoolean() && r.nextBoolean() && r.nextBoolean(); // FP } }
This is a false positive because
r.nextBoolean()
returns a different value each time and has the side effect of changing the state hidden inr
. S1764 should not report if the arguments contain function calls.Note that even field access is referential transparent only in the case of
final
fields because a field’s contents could be changed by another thread while the binary expression is executed. We might ignore that case, though, and treat field access as referential transparent in the context of this rule.