| Summary: | [1.7] IAE in NumberLiteral#setToken(String) for binary tokens and tokens with underscore | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| Product: | [Eclipse Project] JDT | Reporter: | Deepak Azad <deepakazad> | ||||||||
| Component: | Core | Assignee: | Olivier Thomann <Olivier_Thomann> | ||||||||
| Status: | VERIFIED FIXED | QA Contact: | |||||||||
| Severity: | normal | ||||||||||
| Priority: | P3 | CC: | amj87.iitr, Olivier_Thomann | ||||||||
| Version: | 3.7 | ||||||||||
| Target Milestone: | 3.7.1 | ||||||||||
| Hardware: | PC | ||||||||||
| OS: | Windows XP | ||||||||||
| Whiteboard: | |||||||||||
| Attachments: |
|
||||||||||
I get the same exception with tokens that include a underscore character.
---------------------------------------------------------------
import org.eclipse.jdt.core.dom.AST;
import org.eclipse.jdt.core.dom.NumberLiteral;
public class Snippet {
public static void main(String[] args) {
AST ast = AST.newAST(AST.JLS4);
NumberLiteral literal = ast.newNumberLiteral();
literal.setToken("0xCAFEBABE");
literal.setToken("0xCAFE_BABE"); // exception
literal.setToken("01234");
literal.setToken("01_234"); // exception
literal.setToken("1234");
literal.setToken("1_234"); // exception
literal.setToken("0b1010"); // exception
}
}
---------------------------------------------------------------
Created attachment 193994 [details]
Proposed fix + regression tests
Created attachment 193996 [details]
Proposed fix + regression test
Was too strict in JLS2 and JLS3 mode.
Created attachment 193998 [details]
Proposed fix + regression tests
We need to add special treatment for setSimpleName(..) to handle "enum" and "assert" as valid identifiers in order to be able to create a tree on source where these two values have been used as identifiers.
Released in BETA_JAVA7 branch only. Verified using Eclipse Java 7 Support(Beta) feature patch v20110623-0900. |
Exception in thread "main" java.lang.IllegalArgumentException at org.eclipse.jdt.core.dom.NumberLiteral.setToken(NumberLiteral.java:191) at snippet.Snippet.main(Snippet.java:13) ----------------------------------------------------------------------------- import org.eclipse.jdt.core.dom.AST; import org.eclipse.jdt.core.dom.NumberLiteral; public class Snippet { public static void main(String[] args) { AST ast= AST.newAST(AST.JLS4); NumberLiteral literal= ast.newNumberLiteral(); literal.setToken("0xCAFEBABE"); literal.setToken("01234"); literal.setToken("1234"); literal.setToken("0b1010"); //exception on this line } } ----------------------------------------------------------------------------- The first three setToken(..) calls work nicely, but the fourth call fails.