Bug 33450 - AST: StringLitteral doesn't manage correctly octal escape sequence
Summary: AST: StringLitteral doesn't manage correctly octal escape sequence
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 2.1   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: 2.1 RC2   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 32894
  Show dependency tree
 
Reported: 2003-02-27 11:40 EST by Luc Bourlier CLA
Modified: 2003-03-10 12:31 EST (History)
0 users

See Also:


Attachments
StringLiteral.java (9.37 KB, text/plain)
2003-02-27 11:43 EST, Luc Bourlier CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Luc Bourlier CLA 2003-02-27 11:40:59 EST
RC1

We have a problem in the evaluation engine with octal escape sequences (bug
32894), the problem seems to be the result of an error in
StringLiteral#getLiteralValue(). The implementation manages only octal escape
sequences with 1 digit.

I corrected it in my workspace (see the attachment).
Comment 1 Luc Bourlier CLA 2003-02-27 11:43:21 EST
Created attachment 3751 [details]
StringLiteral.java

a corrected version of StringLiteral
Comment 2 Olivier Thomann CLA 2003-02-27 13:13:37 EST
I prefer this code. It simplifies quite a bit the existing code.

		public String getLiteralValue() {
		String s = getEscapedValue();
		int len = s.length();
		if (len < 2 || s.charAt(0) != '\"' || s.charAt(len-1) != '\"' ) {
			throw new IllegalArgumentException();
		}
		
		Scanner scanner = getAST().scanner;
		char[] source = s.toCharArray();
		scanner.setSource(source);
		scanner.resetTo(0, source.length);
		try {
			int tokenType = scanner.getNextToken();
			switch(tokenType) {
				case Scanner.TokenNameStringLiteral:
					return new String(scanner.getCurrentTokenSourceString());
				default:
					throw new IllegalArgumentException();
			}
		} catch(InvalidInputException e) {
			throw new IllegalArgumentException();
		}
	}

	
Could you please confirm it works in your workspace? I added regression tests on
the ASTConverter tests and they are all green.
Comment 3 Luc Bourlier CLA 2003-02-27 14:45:24 EST
Works like a charm.
Comment 4 Philipe Mulet CLA 2003-02-27 14:58:15 EST
Ok for releasing
Comment 5 Olivier Thomann CLA 2003-02-27 15:00:29 EST
Fixed and released in 2.1 stream.
Regression test added.
Comment 6 Olivier Thomann CLA 2003-03-10 12:31:59 EST
Verified by Luc.