Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8342399

No compiler error for class using sealed interface

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P4 P4
    • None
    • 17, 21, 23, 24
    • tools
    • 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

            Unassigned Unassigned
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: