goxr3plus / goxr3plus/java-stream-player

Change Volatile

Open
#28 3 comments 1 reaction 0 assignees View on GitHub
bug
Dominant language
Java
Stars
158
Forks
36
PR merge metrics
No merged PRs in 30d

Description

Volatile fields:

https://github.com/goxr3plus/java-stream-player/blob/a4aaa94c19f99da6ae46cb2bca60bae62aa41b40/src/main/java/com/goxr3plus/streamplayer/stream/StreamPlayer.java#L72

https://github.com/goxr3plus/java-stream-player/blob/a4aaa94c19f99da6ae46cb2bca60bae62aa41b40/src/main/java/com/goxr3plus/streamplayer/stream/StreamPlayer.java#L78

https://github.com/goxr3plus/java-stream-player/blob/a4aaa94c19f99da6ae46cb2bca60bae62aa41b40/src/main/java/com/goxr3plus/streamplayer/stream/StreamPlayer.java#L111

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.
https://github.com/goxr3plus/java-stream-player/blob/a4aaa94c19f99da6ae46cb2bca60bae62aa41b40/src/main/java/com/goxr3plus/streamplayer/stream/StreamPlayer.java#L483

IntelliJ inspection also complains about Synchronization on a non-final field 'audioLock' in three places, the first being
https://github.com/goxr3plus/java-stream-player/blob/a4aaa94c19f99da6ae46cb2bca60bae62aa41b40/src/main/java/com/goxr3plus/streamplayer/stream/StreamPlayer.java#L202

so you should change audioLock from volatile to final.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.