This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 197972

Summary: Covariant return type override bug not reported
Product: java Reporter: arg
Component: CompilerAssignee: Dusan Balek <dbalek>
Status: RESOLVED WONTFIX    
Severity: normal    
Priority: P3    
Version: 6.x   
Hardware: Macintosh (x86)   
OS: Mac OS X   
Issue Type: DEFECT Exception Reporter:

Description arg 2011-04-21 23:20:31 UTC
There's a Java bug "Problem with interfaces and covariant return type overriding", see: http://bugs.sun.com/view_bug.do?bug_id=6656332

I extended their sample a little, see below.  I'm using JDK 1.6.0 (apparently this bug is fixed in 1.7).  No error is indicated in the edit window.  If you clean and build, you do get a compile error, as expected.  The curious thing is that if you run, the code executes fine without any error messages.

public class NewClass {

    // see http://bugs.sun.com/view_bug.do?bug_id=6656332
    interface A {
        A m();
    }

    interface B extends A {
        B m();
    }

    interface C extends A {
        C m();
    }

    interface D extends B,C {
        D m();
    }

    public class X implements D {

        public D m() {
            return new X();
        }

        public String method() {
            return "HELLO";
        }
    }

    public X getX() {
        return (X) new X().m();
    }

    public static void main(String[] args) {
        NewClass nc = new NewClass();
        System.out.println("TEST " + nc.getX().method());
    }
}
Comment 1 Dusan Balek 2011-04-22 15:27:58 UTC
You probably have "Compile On Save" on. Your source gets compiled by the NB internal compiler (which is based on 7.0 javac) and the compiled class is executed.