Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 354628 - Error in java source when EGL string literal uses escape character
Summary: Error in java source when EGL string literal uses escape character
Status: CLOSED FIXED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: EDT (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-08-12 10:24 EDT by Kathy Carroll CLA
Modified: 2017-02-23 14:15 EST (History)
2 users (show)

See Also:


Attachments
test program (996 bytes, text/plain)
2011-08-19 10:53 EDT, Matt Heitz CLA
no flags Details
ET used by test program (664 bytes, text/plain)
2011-08-19 10:53 EDT, Matt Heitz CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Kathy Carroll CLA 2011-08-12 10:24:05 EDT
EGL code

pattern string = "ab\\*[abcd][abcde][^a-e]";
pattern = "ab\\%def";

Java Message:

Invalid escape sequence (valid ones are \b \t \n \f \r \" \' \\ )

JS code is fine
Comment 1 Matt Heitz CLA 2011-08-12 11:25:48 EDT
Resolving with Kathy's consent.  The problem doesn't happen for me, but she's seen it come and go.
Comment 2 Kathy Carroll CLA 2011-08-15 14:34:24 EDT
verified no longer happens for me
Comment 3 Matt Heitz CLA 2011-08-19 10:53:27 EDT
Created attachment 201800 [details]
test program
Comment 4 Matt Heitz CLA 2011-08-19 10:53:55 EDT
Created attachment 201801 [details]
ET used by test program
Comment 5 Matt Heitz CLA 2011-08-19 10:58:55 EDT
This is happening to me now, intermittently.  It seems to happen when generation happens because of a clean, but not when generation happens because I modified the file.

I've attached my testcase (two files).

I set a conditional breakpoint in the generator, at line 21 of org.eclipse.edt.gen.java.templates.StringLiteralTemplate .  The condition is expr.toString().indexOf("\\") > -1

When the problem happens, the value of "expr" in the variables view looks like this:

Instance of: org.eclipse.edt.mof.egl.StringLiteral
	eClass -> Instance of: org.eclipse.edt.mof.EClass - org.eclipse.edt.mof.egl.StringLiteral
	annotations -> [Instance of: EGL_Location]
	value -> c:\temp\test2\this2\stuff2
	isHex -> false

Notice the single backslashes in the value slot.  When the problem doesn't happen the value slot looks like this:

	value -> c:\\temp\\test2\\this2\\stuff2

The IR file always looks good.  For example
<arguments ID="39" eClass="org.eclipse.edt.mof.egl.StringLiteral" value="c:\\temp\\test2\\this2\\stuff2" isHex="false" >
Comment 6 Matt Heitz CLA 2011-08-19 10:59:20 EDT
Meant to reopen.  Duh.
Comment 7 Paul Harmon CLA 2011-09-13 16:07:21 EDT
I found that the root of this problem was that the XMLSeralizer was adding an extra \ whenever it found a \ in a string attribute value. However, since xml does not escape the \ character, this had the effect of adding extra slashes to the string. Because of this, java and javascript generation had removed the code to escape the \ character when it found it in a string literal. Soooo everything worked fine, as long as the generators were invoked from a deserialized copy of the IR (this would happen during an incremental build). However, during a clean build, the generators use the cached IRs that were built during by EDT builder. These IRs do not contain the extra \ characters. Because of this, the java and javascript were generated with insufficient \ characters.

I have updated XMLSerializer to remove the addition of the extraneous \, and have updated StringLiteralTemplate (for both java and js) to escape the \ character.
Comment 8 Kathy Carroll CLA 2011-09-16 14:39:13 EDT
works correctly in 201109161325
Comment 9 Lisa Lasher CLA 2011-10-11 16:19:29 EDT
Closing this defect.