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

Questionable redefinition of audioInputStream #55

Open
HelgeStenstrom opened this issue Dec 13, 2019 · 0 comments
Open

Questionable redefinition of audioInputStream #55

HelgeStenstrom opened this issue Dec 13, 2019 · 0 comments
Assignees
Labels

Comments

@HelgeStenstrom
Copy link
Collaborator

This looks a bit weird in my eyes

// Create decoded Stream
audioInputStream = AudioSystem.getAudioInputStream(targetFormat, audioInputStream);

audioInputStream is a field which is given a value in initAudioInputStream()

// Audio resources from file||URL||inputStream.
audioInputStream = source.getAudioInputStream();

Then it is redefined, i.e., it loses its old value and get a new one. Why isn't a different variable (field) used for the new value?

There is another issue with the assignment on line 507:

Non-atomic operation on volatile field 'audioInputStream'
Inspection info: Reports any non-atomic operations on volatile fields. Non-atomic operations on volatile fields are operations where the field is read and the value is used to update the field. It is possible for the value of the field to change between the read and the write, possibly invalidating the operation. The non-atomic operation can be avoided by surrounding it with a synchronized block or by making use of one of the classes from the java.util.concurrent.atomic package.

As mentioned earlier, it's probably a mistake to make audioInputStream volatile. SonarQube issues a warning where the volatile field is declared. For a description, 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

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