Skip to content

False positive SING_SINGLETON_HAS_NONPRIVATE_CONSTRUCTOR with reused instances #2934

@rovarga

Description

@rovarga

Singleton detection seems to be over-eager. A bit of nest-private hierarchy, like demonstrated in https://github.com/opendaylight/yangtools/blob/2e257731e354e6cc2fd45a6f6eec79bd01490c07/common/yang-common/src/main/java/org/opendaylight/yangtools/yang/common/CanonicalValueViolation.java triggers three singleton errors:

  [ERROR] Medium: Instance-getter method of class using singleton design pattern (org.opendaylight.yangtools.yang.common.CanonicalValueViolation) is not synchronized. [org.opendaylight.yangtools.yang.common.CanonicalValueViolation] At CanonicalValueViolation.java:[line 98] SING_SINGLETON_GETTER_NOT_SYNCHRONIZED
[ERROR] Medium: Class (org.opendaylight.yangtools.yang.common.CanonicalValueViolation) using singleton design pattern has non-private constructor. [org.opendaylight.yangtools.yang.common.CanonicalValueViolation] At CanonicalValueViolation.java:[line 32] SING_SINGLETON_HAS_NONPRIVATE_CONSTRUCTOR
[ERROR] Medium: Class (org.opendaylight.yangtools.yang.common.CanonicalValueViolation) using singleton design pattern directly or indirectly implements Serializable interface. [org.opendaylight.yangtools.yang.common.CanonicalValueViolation] At CanonicalValueViolation.java:[lines 32-158] SING_SINGLETON_IMPLEMENTS_SE

The problem is that CanonicalValueViolation is assumed to be a singleton, whereas it only uses two constants for common instantiateions.

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