eclipse-ee4j / grizzly

Grizzly
https://eclipse-ee4j.github.io/grizzly
Other
147 stars 68 forks source link

SpotBugs analysis: Questionable use of non-short-circuit logic #2181

Closed ghost closed 11 months ago

ghost commented 1 year ago

Is this code correct? If so, perhaps a comment noting that the bitwise-and is intentional?

https://github.com/eclipse-ee4j/grizzly/blob/a2ce7775658e11fbccbb9acd32e2daf2b0799f45/modules/grizzly/src/main/java/org/glassfish/grizzly/memory/BuffersBuffer.java#L738

Questionable use of non-short-circuit logic This code seems to be using non-short-circuit logic (e.g., & or |) rather than short-circuit logic (&& or ||). Non-short-circuit logic causes both sides of the expression to be evaluated even when the result can be inferred from knowing the left-hand side. This can be less efficient and can result in errors if the left-hand side guards cases when evaluating the right-hand side can generate an error.

The line has been present since at least 2.3.25, probably earlier.

ghost commented 11 months ago

@arjantijms -- do you have a link to where the fix (or comment) has gone in? I can't seem to find the PR or change anywhere.