Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change Volatile #28

Open
HelgeStenstrom opened this issue Sep 4, 2019 · 3 comments
Open

Change Volatile #28

HelgeStenstrom opened this issue Sep 4, 2019 · 3 comments
Labels

Comments

@HelgeStenstrom
Copy link
Collaborator

Volatile fields:

private volatile Status status = Status.NOT_SPECIFIED;

private volatile AudioInputStream audioInputStream;

private volatile Object audioLock = new Object();

SonarLint says that you should remove volatile from these fields.
See https://wiki.sei.cmu.edu/confluence/display/java/CON50-J.+Do+not+assume+that+declaring+a+reference+volatile+guarantees+safe+publication+of+the+members+of+the+referenced+object

IntelliJ complains about non-atomic operation on volatile field, probably as a consequence.

audioInputStream = AudioSystem.getAudioInputStream(targetFormat, audioInputStream);

IntelliJ inspection also complains about Synchronization on a non-final field 'audioLock' in three places, the first being

so you should change audioLock from volatile to final.

@goxr3plus
Copy link
Owner

We will have multithreading issues if you remove volatile .

@HelgeStenstrom
Copy link
Collaborator Author

Have you read https://wiki.sei.cmu.edu/confluence/display/java/CON50-J.+Do+not+assume+that+declaring+a+reference+volatile+guarantees+safe+publication+of+the+members+of+the+referenced+object

You might have multithreading issues already.

@HelgeStenstrom
Copy link
Collaborator Author

Issues #1 and #15 might be regarded as multithreading issues, I think.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants