Skip to content

False Negative : Unsynchronized overrides of synchronized methods are missed #5675

@Carlson-JLQ

Description

@Carlson-JLQ

False Negative : Unsynchronized overrides of synchronized methods are missed

Affects errorprone Version:

2.48.0

Checker:

UnsynchronizedOverridesSynchronized

Description:

The official UnsynchronizedOverridesSynchronized checker warns when a subclass overrides a synchronized method with a method that is not synchronized. Both samples below match that description directly.

Code Sample demonstrating the issue:

// PosCase1
static class Parent {
    synchronized void method() {}
}

static class Child extends Parent {
    @Override
    void method() {
        // non-synchronized override
    }
}

// Sonar PosCase1
static class Parent {
    synchronized void synchronizedMethod() {
        System.out.println("Parent synchronized method");
    }
}

static class Child extends Parent {
    @Override
    void synchronizedMethod() {
        System.out.println("Child non-synchronized override");
    }
}

In both cases, the subclass removes the synchronized modifier from an overridden method, which weakens the thread-safety contract promised by the parent type.

Expected outcome:

Error Prone should report these overrides under UnsynchronizedOverridesSynchronized, but it doesn't. This is a false-negative.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions