JDK-8162946 : Casting 'this' from anonymous class to arbitrary interface succeeds
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 9
  • Priority: P2
  • Status: Resolved
  • Resolution: Not an Issue
  • Submitted: 2016-08-02
  • Updated: 2016-08-31
  • Resolved: 2016-08-31
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 9
9Resolved
Related Reports
Relates :  
Relates :  
Description
Let's consider following code:

interface I {}

class Test {
    void foo() {
        new Object() {
            I bar() {
                return (I)this;
            }
        };
    }
}

This code compiles successfully by javac from JDK build 128. However compilation should fail on 'return (I)this;' because the anonymous class doesn't have any relation to interface I.
Comments
Per JDK-8161009, this is correct behavior.
31-08-2016

this regression was provoked by JDK-8161013
10-08-2016