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

[java] A false positive about the rule THREAD_SAFETY_VIOLATION #1793

Open
LynnBroe opened this issue Sep 28, 2023 · 0 comments
Open

[java] A false positive about the rule THREAD_SAFETY_VIOLATION #1793

LynnBroe opened this issue Sep 28, 2023 · 0 comments

Comments

@LynnBroe
Copy link

LynnBroe commented Sep 28, 2023

Version. Infer version v1.1.0
OS. Ubuntu 22.04.3 LTS
Command. infer run -- mvn clean compile

I found a false positive about the rule THREAD_SAFETY_VIOLATION.

According to the description of the rule, infer should not check the method annotated with @VisibleForTesting.
In the example below, however, infer report a THREAD_SAFETY_VIOLATION warning at line 16

import javax.annotation.concurrent.ThreadSafe;
import android.support.annotation.VisibleForTesting;
@ThreadSafe
public class B {
    boolean mField;
    void writeUnderLockOk() {
        synchronized (this) {
            mField = true;
        }
    }
    @VisibleForTesting
    boolean readOutsideLock1Bad() {
        synchronized (this) {}
        return mField;
    }
}
warning: Thread Safety Violation Read/Write race. Non-private method `B.readOutsideLock1Bad()` reads without synchronization from `this.mField`. Potentially races with write in method `B.writeUnderLockOk()`.
Reporting because the current class is annotated `@ThreadSafe`, so we assume that this method can run in parallel with other non-private methods in the class (including itself).

Hence, I think it is a fasle positive.

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

No branches or pull requests

1 participant