Skip to content

False positive when making a package-private class public that already has a public static method's different return type #365

@garydgregory

Description

@garydgregory

I don't see how this breaks binary compatibility:

  • Define a package private class C with a public static method M that returns interface F, release that as version N
  • For version N+1:
    • Change the return type of M to a concrete implementation of F (the kind return type change should not matter)
    • Run JApiCmp and all is well, obviously, since this C is a package-private class
    • Change the visibility of C from package-private to public
    • JApiCmp now fails.

The failure does not make sense since no one outside the package could call C in version N.
For example:

  • git clone -n https://gitbox.apache.org/repos/asf/commons-io.git
  • git checkout 877b9e3f5e553f8ad988b89b8adb6b93fa97a964
  • Make the class org.apache.commons.io.StreamIterator public
  • Run mvn clean install -DskipTests japicmp:cmp -Dcommons.japicmp.version=0.18.1
[ERROR] Failed to execute goal com.github.siom79.japicmp:japicmp-maven-plugin:0.18.1:cmp (default-cli) on project commons-io: There is at least one incompatibility: org.apache.commons.io.filefilter.PathMatcherFileFilter:METHOD_ABSTRACT_ADDED_IN_IMPLEMENTED_INTERFACE,org.apache.commons.io.function.Uncheck.get(org.apache.commons.io.function.IOSupplier,java.util.function.Supplier):CLASS_GENERIC_TEMPLATE_CHANGED,org.apache.commons.io.StreamIterator.iterator(java.util.stream.Stream):METHOD_RETURN_TYPE_CHANGED -> [Help 1]

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