Community
Participate
Working Groups
Eclipse: 3.1 M6 When I parse very simple compilation unit and ask for charValue() for '\0', I receive following exception: java.lang.IllegalArgumentException: illegal character literal Test case: public class TestCharacterLiteral { public static void main(String[] args) { System.out.println('\0'); } }
I just found this bug as well. It appears to be a special case of a bug that arises for any octal escape sequence of fewer than 3 characters. Test code: public static void testCharBugCase(String charLiteral) { try { String src = "class C { char ch = " + charLiteral + "; }"; //System.out.println(src); ASTParser parser = ASTParser.newParser(AST.JLS3); parser.setSource(src.toCharArray()); CompilationUnit ast = (CompilationUnit) parser.createAST(null); TypeDeclaration td = (TypeDeclaration) ast.types().get(0); FieldDeclaration fd = (FieldDeclaration) td.bodyDeclarations().get(0); VariableDeclarationFragment f = (VariableDeclarationFragment) fd.fragments().get(0); CharacterLiteral cl = (CharacterLiteral) f.getInitializer(); System.out.println("Test char literal:" + cl); System.out.println(" Passed, value: " + cl.charValue()); } catch (Exception e) { System.out.println(" Failed, " + e); //e.printStackTrace(); } } public static void testCharBug() { testCharBugCase("'\\0'"); // FAILS testCharBugCase("'\\00'"); // FAILS testCharBugCase("'\\000'"); // WORKS testCharBugCase("'\\40'"); // FAILS testCharBugCase("'\\040'"); // WORKS }
I believe this has been fixed with fix for bug 109940. I will add new regression tests. *** This bug has been marked as a duplicate of 109940 ***
Regression test added in org.eclipse.jdt.core.tests.dom.ASTConverterTestAST3_2.test0622
Verified for 3.2 M3 using ASTView and build I20051025-0800+v_619