"java.lang.NoSuchFieldError: super" exception - bug in compiler?

1.7k Views Asked by At

The following code written in Java-9 being run gives me a very weird and funny exception in runtime:

Exception in thread "main" java.lang.NoSuchFieldError: super
    at A$C.test(A.java:15)
    at A.main(A.java:5)

The code:

public class A {
    public static void main(String[] args) {
        new C().test();
    }

    interface B {
        private void test() {
        }
    }

    static class C implements B {
        void test() {
            B.super.test();
        }
    }
}

I am wondering: is it designed so, or ideally this code shouldn't be compiled, and therefore this is a compiler bug? (I personally believe that this is a bug).

UPD: Submitted a bug, ID : 9052188

UPD-2: It looks like B.super.test() is generally a valid construction, because if test() method is default than it works fine. This fact just makes things more complicated.

1

There are 1 best solutions below

0
On BEST ANSWER

In the end this issue was admitted as a bug by the Java Developer Support team, here is a link: https://bugs.java.com/bugdatabase/view_bug.do?bug_id=JDK-8194847