instanceMethods returns inherited methods with lower visibility than interface method

Issue #152 invalid
errt created an issue

When a non-public method is inherited from by a class that implements an interface that defines the same method, that method must be overridden to lift the visibility to public. Therefore, the inherited method can not be the target of a virtual call anymore. Therefore, it should not be returned by Project.instanceMethods for interfaces/abstract classes that inherit it without overriding it.

This currently happens for java.text.AttributedCharacterIterator that inherits protected Object clone() from java.lang.Object but implementors of AttributedCharacterIterator must override it because that extends java.text.CharacterIterator that defines (public) Object clone().

Comments (2)

  1. Michael Eichberg repo owner

    though the following code is not valid Java, it is valid bytecode and instanceMethods does the correct thing:

    public interface Intf {
        void m();
    }
    public class Sub extends Top implements Intf {
    
    }
    public class Top {
    
        protected void m() {
            System.out.println("Top.m");
        }
    
        public static void main(String[] args) {
            new Sub().m();
        }
    }
    

    In this scenario, main can successfully be executed and "Top.m" will be printed.

  2. Log in to comment