Community
Participate
Working Groups
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); } } } } -------------------------------------------------------------------------
The error msg could be similar to - "Binary literals can only be used with source level greater or equals to 1.7"
Perhaps I am missing something here: The compiler reports already: "Resource specification not allowed here for source level below 1.7" ???
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.
(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
I don't see a bug here - only intended behavior with analogous precedents. (see comment# 5) Hence resolving this as INVALID.
I'll reassign it to inbox, so someone willing & able to pursue this can do so, if he/she deems fit to do so.
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.
Released in BETA_JAVA7 branch.
Thanks Satyam! I am happy from the UI perspective.
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?
(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.
Verified using patch feature 1.0.0-20110623-0900