Bug 92866 - CharacterLiteral.charValue fails for '\0'
Summary: CharacterLiteral.charValue fails for '\0'
Status: VERIFIED DUPLICATE of bug 109940
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows XP
: P3 normal with 1 vote (vote)
Target Milestone: ---   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-04-27 01:11 EDT by Konstantin Scheglov CLA
Modified: 2005-10-31 03:48 EST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Konstantin Scheglov CLA 2005-04-27 01:11:32 EDT
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');
	}
}
Comment 1 David Mandelin CLA 2005-10-03 17:30:59 EDT
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
    }
    
Comment 2 Olivier Thomann CLA 2005-10-04 09:04:25 EDT
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 ***
Comment 3 Olivier Thomann CLA 2005-10-04 09:39:03 EDT
Regression test added in
org.eclipse.jdt.core.tests.dom.ASTConverterTestAST3_2.test0622
Comment 4 Frederic Fusier CLA 2005-10-31 03:48:04 EST
Verified for 3.2 M3 using ASTView and build I20051025-0800+v_619