Bug 387444 - Softening exception in try-with-resources
Summary: Softening exception in try-with-resources
Status: RESOLVED FIXED
Alias: None
Product: AspectJ
Classification: Tools
Component: Compiler (show other bugs)
Version: 1.7.0   Edit
Hardware: PC Windows Vista
: P3 normal (vote)
Target Milestone: 1.7.1   Edit
Assignee: aspectj inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-08-16 20:46 EDT by Emanuel Rabina CLA
Modified: 2012-08-23 15:30 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Emanuel Rabina CLA 2012-08-16 20:46:55 EDT
From this post on the Eclipse AJDT forum: http://www.eclipse.org/forums/index.php/t/369503/

When softening exceptions, AspectJ doesn't seem to soften the exception thrown by the automatic close() invocation when using the try-with-resources syntax introduced in Java 7 (often an IOException).  eg:

---
In Java code:

try (BufferedReader reader = new BufferedReader(new FileReader("test.txt"))) {
  System.out.println(reader.readLine());
}


In AspectJ code:

declare soft: IOException: within(*)

---
The above will result in a compilation error, "Unhandled exception type IOException thrown by automatic close() invocation".

A workaround is to add a catch for the IOException, or to add a throws clause to the method, which kind of makes the exception softening somewhat redundant.

If you're using AJDT, doing these workarounds then adds AJDT add markers to the try-with-resources block, one of which looks like it's for the automatic close() - maybe the 'unhandled exception' error is preventing AspectJ from properly softening the exception?
Comment 1 Andrew Clement CLA 2012-08-23 15:30:53 EDT
fixed.  problem was due to a different path through the compiler that is used for the autoclose case.