Sonar: Make Attempt transient in RetryException #67
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Mark the Attempt field in RetryException as transient to make Sonar
happy.
While technically Sonar rule java:S1948 (Fields in a "Serializable"
class should either be transient or serializable) is true, it seems
highly unlikely that an exception would be serialized to disk during
any processing. The rule gives the example of a JEE application server
flushing objects to disk under heavy load, but again it seems very
unlikely that an exception would ever be serialized, since exceptions
generally need to be handled (or simply propagated) "right now".
If I am wrong about this behavior and a RetryException ever gets
serialized to disk, and then gets de-serialized somewhere else, and then
someone attempts (ha, a pun) to call getNumberOfFailedAttempts(), they
could get a NPE. While not lovely, I'm not going to (at present unless
someone shows me a real-life example of this happening) modify the
getNumberOfFailedAttempts() method to handle this case other than to
check that the lastFailedAttempt is non-null, and throw an
IllegalStateException if it actually is null. So they will receive
an IllegalStateException with an explanation instead of an NPE, which
ultimately I suppose is better.