Assigning weaker access to interface method
Issue #92
resolved
JastAddJ 7.1.1-268-ge381205 Java SE 7
It is possible to implement an interface method with weaker access privileges. To do this, extend a class not implementing the interface with an equivalent declaration to the one in the implementing class.
// Test assigning weaker access to implemented interface method
// .result=COMPILE_FAIL
interface I {
void m();
}
class A {
void m() {
}
}
class Test extends A implements I {
void m() {// error: weaker access privileges
}
}
Comments (3)
-
reporter -
reporter This bug is caused by the
ancestorMethods
attribute not including interface methods for the class it is evaluated for if an ancestor method is found in its direct superclass. This is an error because it leads to the circumvention of the access modifier overriding checks. Simple fix for this is to always add interface methods in theancestorMethods
set. In LookupMethod.jrag at line 511:set = set.add(m); } } - if (set.size() != 1 || ((MethodDecl)set.iterator().next()).isAbstract()) { for (Iterator iter = interfacesMethodsSignature(signature).iterator(); iter.hasNext(); ) { MethodDecl m = (MethodDecl)iter.next(); set = set.add(m); } - } if (!hasSuperclass()) return set; if (set.size() == 1) { MethodDecl m = (MethodDecl)set.iterator().next();
-
reporter - changed status to resolved
- Log in to comment
This also works if the declarations in
A
andTest
are preceded byprotected
.