thrift-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Nathan Marz (JIRA)" <>
Subject [jira] Created: (THRIFT-529) Change generated constructors so that application code evolves better
Date Fri, 26 Jun 2009 20:01:47 GMT
Change generated constructors so that application code evolves better

                 Key: THRIFT-529
             Project: Thrift
          Issue Type: Improvement
          Components: Compiler (Java)
            Reporter: Nathan Marz
            Priority: Minor

The constructors generated by the Java compiler encourage code that breaks when the thrift
definition changes. For example, it is common to add an optional field to a pre-existing schema,

struct Activity {
  1: required i32 id;
  2: required i32 type;
  3: optional i64 timestamp; //newly added

Any code that used the Activity(int, int) constructor will now break.

One option to address this problem is to only generate empty constructors. However, this makes
it cumbersome to create new objects as a line of code is needed to instantiate each field.
A second option is to generate constructors only for required fields. For example, to create
an Activity with a timestamp, the user would need to do the following:

Activity a = new Acitivity(3,4);

This gracefully handles the addition of optional fields. For the case of adding a new required
field, the constructors would break. Arguably this is desired behavior since all the code
would need to be updated anyway, and this way you would be getting compile errors instead
of runtime validation errors.

This message is automatically generated by JIRA.
You can reply to this email to add a comment to the issue online.

View raw message