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

Bug 343687

Summary: [1.7] IAE in NumberLiteral#setToken(String) for binary tokens and tokens with underscore
Product: [Eclipse Project] JDT Reporter: Deepak Azad <deepakazad>
Component: CoreAssignee: 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:
Description Flags
Proposed fix + regression tests
none
Proposed fix + regression test
none
Proposed fix + regression tests none

Description Deepak Azad CLA 2011-04-23 12:01:59 EDT
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.
Comment 1 Deepak Azad CLA 2011-04-24 22:54:15 EDT
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
	}
}
---------------------------------------------------------------
Comment 2 Olivier Thomann CLA 2011-04-25 11:39:19 EDT
Created attachment 193994 [details]
Proposed fix + regression tests
Comment 3 Olivier Thomann CLA 2011-04-25 11:43:47 EDT
Created attachment 193996 [details]
Proposed fix + regression test

Was too strict in JLS2 and JLS3 mode.
Comment 4 Olivier Thomann CLA 2011-04-25 12:04:43 EDT
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.
Comment 5 Olivier Thomann CLA 2011-04-25 12:05:22 EDT
Released in BETA_JAVA7 branch only.
Comment 6 Ayushman Jain CLA 2011-06-29 04:53:17 EDT
Verified using Eclipse Java 7 Support(Beta) feature patch v20110623-0900.