Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 377
Andremoniy Avatar asked Jan 09 '18 19:01

Andremoniy


1 Answers

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

like image 77
Andremoniy Avatar answered Nov 12 '22 16:11

Andremoniy