Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 343687 - [1.7] IAE in NumberLiteral#setToken(String) for binary tokens and tokens with underscore
Summary: [1.7] IAE in NumberLiteral#setToken(String) for binary tokens and tokens with...
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.7   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.7.1   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-04-23 12:01 EDT by Deepak Azad CLA
Modified: 2011-08-05 02:54 EDT (History)
2 users (show)

See Also:


Attachments
Proposed fix + regression tests (4.20 KB, patch)
2011-04-25 11:39 EDT, Olivier Thomann CLA
no flags Details | Diff
Proposed fix + regression test (3.79 KB, patch)
2011-04-25 11:43 EDT, Olivier Thomann CLA
no flags Details | Diff
Proposed fix + regression tests (7.70 KB, patch)
2011-04-25 12:04 EDT, Olivier Thomann CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
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.