-
Bug
-
Resolution: Not an Issue
-
P4
-
None
-
17, 21, 23, 24
-
generic
-
generic
A DESCRIPTION OF THE PROBLEM :
The compiler doesn't give any error when a class implements a sealed interface which is not listed as permitted,
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
package main;
public class IsThisABug {
public static void main(String[] args) {
System.out.println("hello");
}
}
sealed interface TestInterface permits TestInterface2, TestInterface3 {
}
non-sealed interface TestInterface2 extends TestInterface {
}
sealed interface TestInterface3 extends TestInterface {
}
// allowed to implement sealed interface TestInterface3 even if not permitted?
final class TestClass1 implements TestInterface3 {
}
final class TestClass2 implements TestInterface3 {
}
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
compiler error as TestClass1 and TestClass2 are not permitted to implement TestInterface3
ACTUAL -
prints "hello"
CUSTOMER SUBMITTED WORKAROUND :
add one permitted class (e.g. TestClass1) and it will require the rest to add them to the interface's permit
The compiler doesn't give any error when a class implements a sealed interface which is not listed as permitted,
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
package main;
public class IsThisABug {
public static void main(String[] args) {
System.out.println("hello");
}
}
sealed interface TestInterface permits TestInterface2, TestInterface3 {
}
non-sealed interface TestInterface2 extends TestInterface {
}
sealed interface TestInterface3 extends TestInterface {
}
// allowed to implement sealed interface TestInterface3 even if not permitted?
final class TestClass1 implements TestInterface3 {
}
final class TestClass2 implements TestInterface3 {
}
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
compiler error as TestClass1 and TestClass2 are not permitted to implement TestInterface3
ACTUAL -
prints "hello"
CUSTOMER SUBMITTED WORKAROUND :
add one permitted class (e.g. TestClass1) and it will require the rest to add them to the interface's permit