[MDSAL-529] Java codegen fails to escape eligible Unicode escapes Created: 06/Mar/20  Updated: 06/Mar/20  Resolved: 06/Mar/20

Status: Resolved
Project: mdsal
Component/s: Binding codegen
Affects Version/s: None
Fix Version/s: 6.0.0, 5.0.10, 4.0.12

Type: Bug Priority: Medium
Reporter: Robert Varga Assignee: Robert Varga
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

https://docs.oracle.com/javase/specs/jls/se8/html/jls-3.html#jls-3.3 specifies processing of Unicode escapes which happens before the source is being parsed. Most notably it contains the following:

 

If an eligible \ is followed by u, or more than one u, and the last u is not followed by four hexadecimal digits, then a compile-time error occurs.
            

This is very easily triggered by a model like:

 

module def {
  namespace def;
  prefix def;

  leaf def {
    type string;
    default "\\u@\\h\\M% ";
  }
}

where the snippet emitted for javadoc purposes will end up containing what looks like an eligible escape:

/**
 *
 * <p>
 * This class represents the following YANG schema fragment defined in module <b>def</b>
 * <pre>
 * module def {
 *   namespace def;
 *   prefix def;
 *   leaf def {
 *     type string;
 *     default "\u@\h\M% ";
 *   }
 * }
 * </pre>
 *
 */


 Comments   
Comment by Robert Varga [ 06/Mar/20 ]

This may actually be a problem in YANG snippet generator, as that would be the entity responsible for correctly escaping the raw string (as it is using double quotes). A valid solution, though, would end up using single quotes, in which case there would be no need to escape – and the problem is back in our court. As it is the java-api-generator which knows the result is supposed to be a Java file, it needs to deal with whatever comes at it in a way compatible with JLS.

Generated at Wed Feb 07 20:10:01 UTC 2024 using Jira 8.20.10#820010-sha1:ace47f9899e9ee25d7157d59aa17ab06aee30d3d.