Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 348406 - [1.7] Incorrect error msg on try with resources in 1.5 mode
Summary: [1.7] Incorrect error msg on try with resources in 1.5 mode
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.7   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: 3.7.1   Edit
Assignee: Satyam Kandula CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-06-06 10:43 EDT by Deepak Azad CLA
Modified: 2011-08-05 02:54 EDT (History)
5 users (show)

See Also:


Attachments
Proposed patch (2.90 KB, patch)
2011-06-07 06:38 EDT, Satyam Kandula CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Deepak Azad CLA 2011-06-06 10:43:52 EDT
Try the following snippet in 1.5 mode. You will get this error - "The resource type LineNumberReader has to be a subclass of java.lang.AutoCloseable". This is wrong, it should be a syntax error.

-----------------------------------------------------------------------
package org.eclipse;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.LineNumberReader;

public class TryWithResources {
	public static void main(String[] args) throws Throwable {
		try (LineNumberReader reader =
				new LineNumberReader(
						new BufferedReader(
								new FileReader("C:\\test.txt")))) {
			String line;
			while ((line = reader.readLine()) != null) {
				System.out.println(line);
			}
		}
	}
}
-------------------------------------------------------------------------
Comment 1 Deepak Azad CLA 2011-06-06 10:45:14 EDT
The error msg could be similar to - "Binary literals can only be used with source level greater or equals to 1.7"
Comment 2 Srikanth Sankaran CLA 2011-06-06 10:50:48 EDT
Perhaps I am missing something here: 

The compiler reports already:

"Resource specification not allowed here for source level below 1.7"

???
Comment 3 Deepak Azad CLA 2011-06-06 11:10:13 EDT
The compiler reports 2 errors, the one I mentioned and the one you mention. I have the same arguments as Bug 348402 comment 3 and Bug 348402 comment 4. 

In my opinion only "Resource specification not allowed here for source level below 1.7" should be reported.
Comment 4 Srikanth Sankaran CLA 2011-06-06 11:21:13 EDT
(In reply to comment #3)
> The compiler reports 2 errors, the one I mentioned and the one you mention. I
> have the same arguments as Bug 348402 comment 3 and Bug 348402 comment 4. 
> 
> In my opinion only "Resource specification not allowed here for source level
> below 1.7" should be reported.

See bug bug 348402 comment 5
Comment 5 Srikanth Sankaran CLA 2011-06-06 13:30:42 EDT
I don't see a bug here - only intended behavior with analogous precedents.
(see comment# 5) Hence resolving this as INVALID.
Comment 6 Srikanth Sankaran CLA 2011-06-07 01:27:07 EDT
I'll reassign  it to inbox, so someone willing & able to pursue this
can do so, if he/she deems fit to do so.
Comment 7 Satyam Kandula CLA 2011-06-07 06:38:48 EDT
Created attachment 197487 [details]
Proposed patch

I think it will be good to show only one error message in this case. 
To minimize any impact, I just added the check before reporting the error.
Comment 8 Satyam Kandula CLA 2011-06-07 07:43:02 EDT
Released in BETA_JAVA7 branch.
Comment 9 Deepak Azad CLA 2011-06-07 08:13:57 EDT
Thanks Satyam! I am happy from the UI perspective.
Comment 10 Stephan Herrmann CLA 2011-06-28 10:41:51 EDT
Just for documenting the impact of the change: also the this:

        try (Object o = new Object()) {
        	
        }

now triggers only one error. Only after changing the compliance to 1.7
the secondary error shows up:

  The resource type Object has to be a subclass of java.lang.AutoCloseable

I assume this works as intended?
Comment 11 Srikanth Sankaran CLA 2011-06-28 11:35:47 EDT
(In reply to comment #10)
> Just for documenting the impact of the change: also the this:

> I assume this works as intended?

Yes, this is the intended behavior. At 1.6-, we don't want to
say anything about AutoCloseable which is a 1.7+ feature.
Comment 12 Stephan Herrmann CLA 2011-06-28 12:18:31 EDT
Verified using patch feature 1.0.0-20110623-0900