| Summary: | ASTParser.setSource has a different behavior from ASTParser.createASTs when there is an invalid if() statement | ||||||
|---|---|---|---|---|---|---|---|
| Product: | [Eclipse Project] JDT | Reporter: | Tsantalis Nikolaos <tsantalis> | ||||
| Component: | Core | Assignee: | JDT-Core-Inbox <jdt-core-inbox> | ||||
| Status: | CLOSED INVALID | QA Contact: | |||||
| Severity: | normal | ||||||
| Priority: | P3 | CC: | Olivier_Thomann | ||||
| Version: | 4.11 | ||||||
| Target Milestone: | --- | ||||||
| Hardware: | PC | ||||||
| OS: | Windows 10 | ||||||
| Whiteboard: | |||||||
| Attachments: |
|
||||||
Did you try to use: org.eclipse.jdt.core.dom.ASTParser.setStatementsRecovery(boolean) (In reply to Olivier Thomann from comment #1) I enabled statements recovery and it worked. I am sorry for taking your time with this problem, but I migrated my code from ASTParser.createASTs() to ASTParser.setSource() and I found this difference in my test results. Thank you again! |
Created attachment 277431 [details] Input Java file to replicate the bug Method read() in the attached file contains an invalid if() statement in line 82, which has no conditional expression and body. When using the ASTParser.setSource(char[]) method to parse the code, the generated compilation unit has an empty method body for read(). However, when using the ASTParser.createASTs(String[] sourceFilePaths, String[] encodings, String[] bindingKeys, FileASTRequestor requestor, IProgressMonitor monitor) method to parse the code, the generated compilation unit has a non-empty body for read(), and simply omits the invalid if() from the AST. What is the reason for this different behavior? Is it possible to setup the ASTParser to simply ignore such invalid code structures when using ASTParser.setSource() instead of generating an empty method?