Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 497609

Summary: Stop marking anonymous classes as final when JDK-8161009 is resolved
Product: [Eclipse Project] JDT Reporter: Stephan Herrmann <stephan.herrmann>
Component: CoreAssignee: Stephan Herrmann <stephan.herrmann>
Status: CLOSED DUPLICATE QA Contact:
Severity: normal    
Priority: P3 CC: jarthana, manoj.palat, sasikanth.bharadwaj
Version: 4.6   
Target Milestone: BETA J9   
Hardware: PC   
OS: Linux   
Whiteboard:

Description Stephan Herrmann CLA 2016-07-09 16:02:16 EDT
In https://bugs.openjdk.java.net/browse/JDK-8161009 Dan surprisingly proposed to drop a useful line from the spec in favor of long standing behavior of javac (and ecj).

When JDK-8161009 is resolved we should then stop internally marking anonymous classes as final. 

While focus in related JDK-bugs is on not incompatibly changing serialization, in my understanding this will also affect castability, i.e., the JLS change will likely imply that this bogus program:

//---
class Test231 implements Test231i {
  void foo() {
    new Object() {
      Test231i bar() {
        return (Test231i)this;
      }
    };
  }
}

interface Test231i { }
//---

should be accepted. Currently we correctly report:

----------
1. ERROR in /tmp/Test231.java (at line 10)
        return (Test231i)this;
               ^^^^^^^^^^^^^^
Cannot cast from new Object(){} to Test231i
----------

Also javac rejects this program.

Let's watch the discussion in JDK-8161009
Comment 1 Stephan Herrmann CLA 2017-05-25 15:22:34 EDT
(In reply to Stephan Herrmann from comment #0)
> In https://bugs.openjdk.java.net/browse/JDK-8161009 Dan surprisingly
> proposed to drop a useful line from the spec in favor of long standing
> behavior of javac (and ecj).
> 
> When JDK-8161009 is resolved we should then stop internally marking
> anonymous classes as final. 
> 
> While focus in related JDK-bugs is on not incompatibly changing
> serialization, in my understanding this will also affect castability, i.e.,
> the JLS change will likely imply that this bogus program:
> 
> //---
> class Test231 implements Test231i {
>   void foo() {
>     new Object() {
>       Test231i bar() {
>         return (Test231i)this;
>       }
>     };
>   }
> }
> 
> interface Test231i { }
> //---
> 
> should be accepted. Currently we correctly report:
> 
> ----------
> 1. ERROR in /tmp/Test231.java (at line 10)
>         return (Test231i)this;
>                ^^^^^^^^^^^^^^
> Cannot cast from new Object(){} to Test231i
> ----------
> 
> Also javac rejects this program.
> 
> Let's watch the discussion in JDK-8161009

That bug is marked as resolved in Java 9.
javac9 now accepts the above bogus program.
Comment 2 Manoj N Palat CLA 2018-05-16 01:06:44 EDT
bulk move out of 4.8
Comment 3 Stephan Herrmann CLA 2018-05-16 05:01:15 EDT
Let's keep it on the radar for 4.9 - we need to adjust to a spec change made in Java 9.
Comment 4 Manoj N Palat CLA 2019-02-11 04:16:53 EST
Bulk move out of 4.11
Comment 5 Manoj N Palat CLA 2019-08-27 02:06:12 EDT
Bulk move out of 4.13
Comment 6 Stephan Herrmann CLA 2019-08-27 08:42:43 EDT
Need to follow the spec change, fix should be simple.
Comment 7 Stephan Herrmann CLA 2019-11-14 13:06:36 EST

*** This bug has been marked as a duplicate of bug 520727 ***