Possible bug with defender method that calls itself
Maurizio Cimadamore
maurizio.cimadamore at oracle.com
Fri Dec 16 03:15:24 PST 2011
The program should give a StackTraceException - however as pointed out
by Robert and Brian, VM support for extension methods is not in place
yet - there are cases (like the one you posted yesterday) in which
things seem to 'just' work, but that's mostly by accident. In the most
general case you will get AbstractMethodErrror if you don't run the
extensin method static weaver on your classes.
Maurizio
On 16/12/11 08:24, Per Rovegård wrote:
> 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