'Non-primitive fields should not be "volatile" for @Immutable and @ThreadSafe annotated types

We have various classes annotated with javax.annotation.concurrent.ThreadSafe and javax.annotation.concurrent.Immutable. These annotations are not recognized before raising issue
'Non-primitive fields should not be “volatile” (java:S3077).

Hey @wbibile

Your report is a bit light in information. Can I suggest you look at the following post, and add more details?


We are using SonarQube developer edition
SonarQube: server 8.4.2
Language: Java

We noticed that SonarQube analysis fails with S3077, for volatile fields whose types are immutable or thread-safe class.

For example:

class MyImmutable

class MyThreadSafe

class Main
    private volatile MyImmutable x;
    private volatile MyThreadSafe y;

I don’t expect a warning about ‘Non-primitive fields should not be “volatile”’ for fields Main.x and Main.y as they are marked immutable or thread-safe.

Hello @wbibile,

Thanks for your feedback. Indeed this makes sense to not report in such cases. Created a ticket for it:



1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.