Kotlin / binary-compatibility-validator

Public API management tool
Apache License 2.0
800 stars 59 forks source link

`protected` method of enum should not be included #158

Open dovchinnikov opened 10 months ago

dovchinnikov commented 10 months ago
package cases.enums;

public enum JavaEnum {
    A {
        @Override
        public void publicAbstractMethod() {
        }

        @Override
        protected void protectedAbstractMethod() {
        }

        @Override
        void packagePrivateAbstractMethod() {
        }
    };

    public abstract void publicAbstractMethod();

    protected abstract void protectedAbstractMethod();

    abstract void packagePrivateAbstractMethod();
}

Expected:

public abstract class cases/enums/JavaEnum : java/lang/Enum {
    public static final field A Lcases/enums/JavaEnum;
    public abstract fun publicAbstractMethod ()V
    public static fun valueOf (Ljava/lang/String;)Lcases/enums/JavaEnum;
    public static fun values ()[Lcases/enums/JavaEnum;
}

Actual:

public abstract class cases/enums/JavaEnum : java/lang/Enum {
    public static final field A Lcases/enums/JavaEnum;
    protected abstract fun protectedAbstractMethod ()V
    public abstract fun publicAbstractMethod ()V
    public static fun valueOf (Ljava/lang/String;)Lcases/enums/JavaEnum;
    public static fun values ()[Lcases/enums/JavaEnum;
}
dovchinnikov commented 10 months ago

protected members of sealed classes are probably affected by the same problem (I didn't check).

fzhinkin commented 9 months ago

Well, JVMS doesn't stop us from having a class extending j.l.Enum, so one theoretically may have a "enum" with non-final protected methods that could be overridden by some other class on the classpath. 😢

What problem you're trying to solve? Do you have a bunch of enums that change constantly?

dovchinnikov commented 9 months ago

What problem you're trying to solve?

I'm trying to minimize the amount of entries in the dump.

Do you have a bunch of enums that change constantly?

Not really. But the same argument can be used for any other member which is hidden from dumps by BCV and which technically constitutes API from JVMS perspective, right? If the argument applies here, then it should be applicable there, and if it's not applicable there, then it should not be considered here.