Possible bug with defender method that calls itself

Per Rovegård per at rovegard.se
Fri Dec 16 00:24:34 PST 2011


Hi,

While testing defender methods, I wrote the following small program:

public class TestDefender2 {
        public static interface A {
                String sayHi() default { return sayHi(); };
        }

        public static class AImpl implements A { }

        public static void main(String[] args) throws Exception {
                System.out.println(new AImpl().sayHi());
        }
}

How should the program behave? I would expect to get one of the following:
a) A compilation error, saying that I try to call an abstract method, or
b) A StackOverflowError at runtime resulting from infinite recursion.

But it compiles successfully and when run it gives:

$ ../lambda/build/linux-amd64/j2sdk-image/bin/java TestDefender2
Exception in thread "main" java.lang.AbstractMethodError:
TestDefender2$AImpl.sayHi()Ljava/lang/String;
        at TestDefender2$A.sayHi(TestDefender2.java:3)
        at TestDefender2.main(TestDefender2.java:9)

Is this a bug?

Br,
Per


More information about the lambda-dev mailing list