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

Bug 365952

Summary: [1.7][quick fix] Quick Fix sees twr resources in catch/finally blocks
Product: [Eclipse Project] JDT Reporter: Paul Benedict <pbenedict>
Component: CoreAssignee: ANIRBAN CHAKRABORTY <anchakrk>
Status: CLOSED WONTFIX QA Contact:
Severity: normal    
Priority: P3 CC: amj87.iitr, jarthana, samrat.dhillon, send2adtc
Version: 3.8   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard: stalebug

Description Paul Benedict CLA 2011-12-07 14:37:01 EST
Build Identifier: 20110916-0149

The spec says:

try ResourceSpecification Block Catches_opt Finally_opt 

"The scope of a variable declared in a resource specification of a try-with-resources statement (ยง14.20) is from the declaration rightward over the remainder of the resource specification and the entire Block associated with the try."

If I do a Quick Fix in the catch/finally block on "is", the resource is available for completion. The variable shouldn't be recognized in the catch/finally block since it is out of scope. Happily, the code doesn't compile when completed, but Quick Fix shouldn't recognize the variable anyway.

Reproducible: Always

Steps to Reproduce:
try (InputStream is = new FileInputStream("C:\\MSG.OUT")) { 
  // empty
} catch (IOException e) {
  is<-- CTRL+1 here
} finally {
  is<-- CTRL+1 here
}
Comment 1 Ayushman Jain CLA 2011-12-07 14:57:54 EST
Do you mean CTRL-SPACE (content assist)? That's what you'll use to complete code right? I can see that 'is' is siggested in the catch block and thats a content assist bug.
Let me know if you intend to report something else.
Comment 2 Paul Benedict CLA 2011-12-07 15:16:45 EST
Yes, the error is from Content Assist (CTRL-SPACE). Thanks for the correction.
Comment 3 Samrat Dhillon CLA 2012-09-01 18:57:28 EDT
There seems to be another problem which I think is related to this behavior. Consider the following block

try{
			
}catch(Exception e){
			
}finally{
 <CTRL+SPACE> e			
}
The codes assist invocation in the finally block incorrectly shows Exception variable e available in the finally block. I think the problem is somewhere in the buildInitialRecoveryState method of org.eclipse.jdt.internal.codeassist.impl.AssistParser. I couldn't continue further with the investigation. Is there some documentation as to how Eclipse AST parser works?
Comment 4 Adtc Rulez CLA 2013-09-09 00:34:32 EDT
Code Completion/Content Assist also shows the resources where it shouldn't be available.

I have posted a question on SO asking about this, and answers/resources confirm this shouldn't be the case. http://stackoverflow.com/questions/18691352

Since we already have this bug, I shan't file a new one. But please look at the question for screenshots.
Comment 5 Jay Arthanareeswaran CLA 2013-09-10 01:17:58 EDT
Anirban,

I am assigning the bug to you. You can perhaps look at after the Java 8 support is complete.
Comment 6 Eclipse Genie CLA 2020-03-11 13:58:59 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. As such, we're closing this bug.

If you have further information on the current state of the bug, please add it and reopen this bug. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.