Hello the smart community,
I have done some research around this issue and couldn't seem to find the answer to my exact problem
I am facing a strange compile-time issue with Java String literals that contain unicode escape codes.
Here is the code snippet under consideration:
String text = textArea.getText().trim();
String unicodeReturn = "\u000A";
text =
"\"" +
text
.replace(" ", "%s")
.replace("\\", "\\\\")
.replace("\"", "\\\"")
.replace("\n", "\u000A")
+
"\"";
I get compile-time error "String literal is not properly closed by a double-quote" for the line
String unicodeReturn = "\u000A";
Strangely, the line
.replace("\n", "\u000A")
where the same unicode literal exists, doesn't seem to cause any issues. I have been using unicode notation syntax for quite some time now. If my memory is not failing me the format is \uXXXX, where X is a hex digit.
My environment is
- JDK 1.8.0_66
- MACOSX El Capitan
- Eclipse Mars.1
My questions are:
- Has anyone come across the same issue?
- Is this a known JDK 1.8 compiler bug?
- Is there a solution or a workaround to this?
- Does anyone know if I am doing something wrong?
(It is quite frustrating and prevents me from compiling my code)