Bug 473762 - Need a way to check exceptions in external DOM classes, in codeassist class ThrownExceptionFinder has method processThrownExceptions, but issues are it only takes TryStatement and it uses internal classes
Summary: Need a way to check exceptions in external DOM classes, in codeassist class T...
Status: NEW
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 4.6   Edit
Hardware: PC Mac OS X
: P3 enhancement with 1 vote (vote)
Target Milestone: ---   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-07-28 10:10 EDT by Md Arefin CLA
Modified: 2015-07-28 10:26 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 Md Arefin CLA 2015-07-28 10:10:00 EDT
we would like to check that a block of code (e.g., a for loop body) does not throw checked exceptions. Note that, if a block of code does throw a checked exception, the code will compile so as long as the method header/signature has a throws clause. Here's an example:

void m() throws Exception {
    for (...) {
        throw new Exception(); //bad.
    }
    for (...) {
        //good.
    }
}

Note that this is not as simple as just checking for throw statements in the AST of the loop body as the body may call methods that throw exceptions and the throw could appear in a try/catch block that does not rethrow the exception.

there is a method org.eclipse.jdt.internal.codeassist.ThrownExceptionFinder.getThrownUncaughtExceptions()
It seems that the method to call first is ThrownExceptionFinder.processThrownExceptions(TryStatement, BlockScope) rather than TryStament we need to check for any kind of statement so that we can find exceptions in an arbitrary statement.
Comment 1 Md Arefin CLA 2015-07-28 10:26:08 EDT
Netbeans also has done similar work at  org.netbeans.api.java.source.TreeUtilities.getUncaughtExceptions() 

we think one solution might be not to use the internal compiler DOM classes 

The forum links are below for this issue:
https://dev.eclipse.org/mhonarc/lists//jdt-core-dev/msg02435.html
https://dev.eclipse.org/mhonarc/lists//jdt-core-dev/msg02446.html