Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compilation error with multiple bounds and package protected abstract method #656

Closed
iloveeclipse opened this issue Jan 24, 2023 · 2 comments · Fixed by #1116
Closed

Compilation error with multiple bounds and package protected abstract method #656

iloveeclipse opened this issue Jan 24, 2023 · 2 comments · Fixed by #1116
Assignees
Labels
bug Something isn't working

Comments

@iloveeclipse
Copy link
Member

iloveeclipse commented Jan 24, 2023

For the code below Eclipse on master reports error on MyGenericClass (project set to use Java 17 JLS).
Javac from Java 17.0.4 accepts the code.

This class must implement the inherited abstract method MyAbstract.someAbstractMethod(), but cannot override it since it is not visible from MyGenericClass. Either make the type abstract or make the inherited method visible
package package1;
import package2.MyAbstract;
import package2.MyInterface;
public class MyGenericClass<T extends MyAbstract & MyInterface> { // removing MyInterface works
}

package package2;
public interface MyInterface {
     void myMethod();
}

package package2;
public abstract class MyAbstract {
	/* package protected! */ abstract void someAbstractMethod();
}

Initially reported at eclipse-platform/.github#85

@srikanth-sankaran
Copy link
Contributor

This is a pretty interesting bug. If in package1, one were to declare a class that extends MyAbstract and implements MyInterface
such as

package package1;
import package2.MyAbstract;
import package2.MyInterface;
public class MyGenericClass<T extends MyAbstract & MyInterface> { // removing MyInterface works
}

class JavacWillAlsoError extends MyAbstract implements MyInterface {

	public void myMethod() {
	}

	void someAbstractMethod() {
	}
}

javac will also complain:

package1/MyGenericClass.java:7: error: JavacWillAlsoError is not abstract and does not override abstract method someAbstractMethod() in MyAbstract
class JavacWillAlsoError extends MyAbstract implements MyInterface {
^
1 error

and rightfully so. In this case you don't need the implements clause also to trigger the error.

Basically In Package1, you can't declare a type that will extend MyAbstract because that class declares an abstract package private method which is invisible in Package1

But the crucial question is whether there can be a type variable T declared in Package1 that can extend MyAbstract. This is certainly legal (so ECJ is wrong to complain) - since T can be instantiated with a type declared in Package2 that extends MyAbstract properly

@srikanth-sankaran srikanth-sankaran self-assigned this May 30, 2023
@srikanth-sankaran
Copy link
Contributor

See https://bugs.eclipse.org/bugs/show_bug.cgi?id=519245 for pretty much the same problem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants