Skip to content

False positive CLASS_NOW_FINAL making a public class final when it has a single private 0-argument constructor #426

@garydgregory

Description

@garydgregory

Over at Apache Commons Compress PR 712, using The Maven plugin version 0.23.1, we are seeing a CLASS_NOW_FINAL when we change a public class to public final class but this class has a private 0-argument constructor:

    /** No instances needed. */
    private TarUtils() {
    }

According to the JLS' binary compatibility specification for Java 21:

If a class that was not declared final is changed to be declared final, then an IncompatibleClassChangeError is thrown if a binary of a pre-existing subclass of this class is loaded, because final classes can have no subclasses; such a change is not recommended for widely distributed classes.

Because our class cannot be subclassed due to its private 0-argument constructor, changing it to final is binary compatible, which is why we think there is a bug when JApiCmp signals CLASS_NOW_FINAL.

I have tested this use case using Java 8, 11, 17, 21, and 25 and I can indeed run such a configuration.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions