[Java] Rule S3077 should (I think) be reworded

In sonarlint, the summary text for the rule violation is “remove the ‘volatile’ keyword from this field”. In a context where this is appearing as in-IDE guidance, I think that wording is actively harmful. It provides seemingly clear instructions for a fix that will, at best, leave the code no better off but may make things worse. I think something like ‘volatile is insufficient for mutable non-primitive fields’ or ‘volatile should be used with caution on Objects’ or really anything that alludes to something more going on would be better.

Hi @cmbalin,

Thank you for your feedback. I agree that removing volatile is only part of the fix.

I’ll replace the message with “replace this ‘volatile’ keyword on an object with a more thread-safe mechanism”. Let me know if you think that it is not clear enough.

Ticket here: https://jira.sonarsource.com/browse/SONARJAVA-3243

Cheers,

1 Like