Bug 33450

Summary: AST: StringLitteral doesn't manage correctly octal escape sequence
Product: [Eclipse Project] JDT Reporter: Luc Bourlier <eclipse>
Component: CoreAssignee: Olivier Thomann <Olivier_Thomann>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3    
Version: 2.1   
Target Milestone: 2.1 RC2   
Hardware: PC   
OS: Linux   
Whiteboard:
Bug Depends on:    
Bug Blocks: 32894    
Attachments:
Description Flags
StringLiteral.java none

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.