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

Bug 352453

Summary: [1.7] In 1.6 project, use of <> in anonymous classes is giving an unexpected error message
Product: [Eclipse Project] JDT Reporter: Satyam Kandula <satyam.kandula>
Component: CoreAssignee: Ayushman Jain <amj87.iitr>
Status: VERIFIED INVALID QA Contact:
Severity: normal    
Priority: P3 CC: amj87.iitr
Version: 3.7   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard:

Description Satyam Kandula CLA 2011-07-19 09:14:01 EDT
Found in BETA_JAVA7 branch for a 1.6 project. 
Type the following program in the package explorer in 1.6 project. 
public class X<T> {  
    public void foo() {
        new X<>("abc") {};
    }  
}
The following errors are reported:
- '<>' operator is not allowed for source level below 1.7
- '<>' cannot be used with anonymous classes

Without the patched version, the message was "The type new X(){} cannot extend or implement X<?>. A supertype may not specify any wildcard". IMO, this message is better.
Comment 1 Ayushman Jain CLA 2011-07-19 09:41:17 EDT
(In reply to comment #0)
> Without the patched version, the message was "The type new X(){} cannot extend
> or implement X<?>. A supertype may not specify any wildcard". IMO, this message
> is better.

I'm not too sure I agree with this message being better. X<> has no business to be interpreted as X<?>. "..A supertype may not specify any wildcard" - where is the wildcard? :)
Comment 2 Srikanth Sankaran CLA 2011-07-19 09:44:46 EDT
(In reply to comment #0)
> Found in BETA_JAVA7 branch for a 1.6 project. 

> Without the patched version, the message was "The type new X(){} cannot extend
> or implement X<?>. A supertype may not specify any wildcard". IMO, this message
> is better.

(My message collided with Ayush's message, reposting)

Satyam, this message is based on suspect recovery. See that there is no
? at all in the source program and we are complaining about it and this can
actually seriously leave a user scratching his/her head. (what supertype
is specifying wildcard ???)

See also bug 349054, in particular
https://bugs.eclipse.org/bugs/show_bug.cgi?id=349054#c2 which shows the effects
of broken recovery.
Comment 3 Satyam Kandula CLA 2011-07-19 10:29:30 EDT
OK, I agree that the previous message is not good, but do you think the present message is correct in a 1.6 project context.
Comment 4 Ayushman Jain CLA 2011-07-19 10:35:04 EDT
(In reply to comment #3)
> OK, I agree that the previous message is not good, but do you think the present
> message is correct in a 1.6 project context.

Yup. This is very much intentional and also consistent with what javac says. See bug 348493.
Comment 5 Ayushman Jain CLA 2011-07-19 10:40:08 EDT
javac 7b147 with -source 1.5 says:
"error: diamond operator is not s
upported in -source 1.5
        new X<>("abc") {};
              ^
  (use -source 7 or higher to enable diamond operator)
1 error
1 warning"

Hence closing as invalid.
Comment 6 Satyam Kandula CLA 2011-07-19 10:56:27 EDT
I am fine with this.