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

False-positive globally reachable private Java vars under -Ycheck-reentrant #20324

Closed
WojciechMazur opened this issue May 2, 2024 · 4 comments
Labels
area:experimental area:private options Issues tied to -Y private/internal compiler settings. itype:bug

Comments

@WojciechMazur
Copy link
Contributor

Compiler version

3.5.0-RC1-bin-20240501-e6bc130-NIGHTLY

Minimized example

Found in Scala 2 compiler forward-port #19897

private val Close = java.nio.CharBuffer.allocate(0)

Output

> scala-cli compile --server=false sandbox.scala -S 3.nightly -Ycheck-reentrant -Ylog:checkReentrant+ 
possible data race involving globally reachable variable isReadOnly in class CharBuffer: Boolean
  use -Ylog:checkReentrant+ to find out more about why the variable is reachable.
possible data race involving globally reachable variable address in class Buffer: Long
  use -Ylog:checkReentrant+ to find out more about why the variable is reachable.
2 errors found
Compilation failed

Expectation

isReadOnly and address are private/package private? variable, first of them can be only accessed via the accessor method. These should not be reported.

@WojciechMazur WojciechMazur added itype:bug area:experimental stat:needs triage Every issue needs to have an "area" and "itype" label labels May 2, 2024
@bishabosha
Copy link
Member

my thought was that it doesn't care about private because all that matters is "is there a mutable field" and so someone could call something public that changes the field

@WojciechMazur
Copy link
Contributor Author

Maybe, that would also make sense. I don't know the scope of -Ycheck-reentrant flag and neither understand it yet, so I'm leaving it to decide how it should be handled.

@Gedochao
Copy link
Contributor

Gedochao commented May 9, 2024

@odersky thoughts on this behaviour?

@Gedochao Gedochao added area:private options Issues tied to -Y private/internal compiler settings. and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels May 9, 2024
@odersky
Copy link
Contributor

odersky commented May 9, 2024

I think that's a reasonable warning. The fix is to annotate Close with @sharable.

@WojciechMazur WojciechMazur closed this as not planned Won't fix, can't repro, duplicate, stale May 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:experimental area:private options Issues tied to -Y private/internal compiler settings. itype:bug
Projects
None yet
Development

No branches or pull requests

4 participants