Search code examples
javastringescapeutils

Apache commons StringEscapeUtils.unescapeJava("\\") returns ""


The following code:

final String INVALID_ESCAPE="\\";
System.out.println(String.format("'%s' -> '%s'", INVALID_ESCAPE, 
    StringEscapeUtils.unescapeJava(INVALID_ESCAPE)));

... produces:

'\' -> ''

on the console. Since '\' is not a valid escape I would expect an Exception at runtime. Am I missing anything?

UPDATE: filled a bug(?) report in Apache jira


Solution

  • From the source:

    // TODO: throw "illegal character: \92" as an Exception if a \ on the end of the Java (as per the compiler)?
    

    Send a patch ;-)