Tom Davis created THRIFT-3709:
---------------------------------

             Summary: Comment syntax can produce broken code
                 Key: THRIFT-3709
                 URL: https://issues.apache.org/jira/browse/THRIFT-3709
             Project: Thrift
          Issue Type: Bug
          Components: Compiler (General)
    Affects Versions: 1.0
            Reporter: Tom Davis


Somewhere between 85650612e15c79c79e470553d3779d18f755150c and 
6ec6860801bdc87236e636add071c4faa2ac7e4b the handling of comments was changed. 
This change appears to have removed support for the syntax {{/** Comment **/}}. 
In particular, the comment-end token can't have more than one asterisk.

However, it is possible to "trick" the parser by having multiple comments:

{code}
struct Thing {
  /** This is a comment */
  1: required string id,
  /** This is also a comment **/
  2: required string typeId,
  /** Yet another comment! */
  3: required i32 endTimestamp
}
{code}

In this case, the IDL file will parse correctly but will produce broken code, 
at least in the case of the Java compiler. Here is the relevant part of the 
generated file, first from the older commit (functional), then from master 
(broken).

{code:java}
  /**
   * This is a comment
   */
  public String id; // required
  /**
   * This is also a comment *
   */
  public String typeId; // required
  /**
   * Yet another comment!
   */
  public int endTimestamp; // required
{code}

{code:java}
  /**
   * This is a comment
   */
  public String id; // required
  /**
   * This is also a comment **/
   * 2: required string typeId,
   * /** Yet another comment!
   */
  public int endTimestamp; // required
{code}

The line {{* 2: required string typeId,}} lives outside the comment so the code 
fails to compile.

For my part, I'll modify my IDL files to only use the single-asterisk syntax. 
However, I would expect generation to fail similarly to how it does with a 
single {{/** Comment **/}} (with a maybe-not-totally-helpful "unexpected token" 
error)



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to