[
https://issues.apache.org/jira/browse/THRIFT-1297?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13091857#comment-13091857
]
Joris van der Wel commented on THRIFT-1297:
-------------------------------------------
I am not sure what is considered null in thrift.
My issue is that .write is not called at all when the expression is falsy
(null, false, undefined, 0, '', NaN). I think the value is not sent over the
network at all. If that is considered as null by the receiving end, it could be
the same issue.
If null and a non existing value are not considered the same, it is a different
issue and strict equality would be needed (!== ===)
> Compiled javascript code does not write falsy values
> ----------------------------------------------------
>
> Key: THRIFT-1297
> URL: https://issues.apache.org/jira/browse/THRIFT-1297
> Project: Thrift
> Issue Type: Bug
> Components: JavaScript - Compiler
> Affects Versions: 0.7
> Environment: Windows 0.7 thrift compiler (pre built)
> http://www.apache.org/dyn/closer.cgi?path=/thrift/0.7.0/thrift-0.7.0.exe
> Thrift 0.7 compiled on Ubuntu shows same symptoms
> Reporter: Joris van der Wel
> Priority: Critical
> Labels: compiler, javascript, regression
>
> I compiled cassandra.thrift using "thrift --gen js:node cassandra.thrift".
> When I use this code this results in the following error from cassandra /
> thrift:
> {code}
> { name: 'TApplicationException', type: 7,
> message: 'Required field \'reversed\' was not found in serialized data!
> Struct : SliceRange(start:null, finish:null, reversed:false, count:100)' }
> {code}
> If I look in the generated code, I find
> {code}
> SliceRange.prototype.write = function(output) {
> output.writeStructBegin('SliceRange');
> if (this.start) {
> output.writeFieldBegin('start', Thrift.Type.STRING, 1);
> output.writeString(this.start);
> output.writeFieldEnd();
> }
> if (this.finish) {
> output.writeFieldBegin('finish', Thrift.Type.STRING, 2);
> output.writeString(this.finish);
> output.writeFieldEnd();
> }
> if (this.reversed) {
> output.writeFieldBegin('reversed', Thrift.Type.BOOL, 3);
> output.writeBool(this.reversed);
> output.writeFieldEnd();
> }
> if (this.count) {
> output.writeFieldBegin('count', Thrift.Type.I32, 4);
> output.writeI32(this.count);
> output.writeFieldEnd();
> }
> output.writeFieldStop();
> output.writeStructEnd();
> return;
> };
> {code}
> this.reversed is false and subsequently does not get sent
> If I look at the compiled version that was generated by 0.6.1 I see:
> {code}
> SliceRange.prototype.write = function(output){
> output.writeStructBegin('SliceRange')
> if (null != this.start) {
> output.writeFieldBegin('start', Thrift.Type.STRING, 1)
> output.writeString(this.start)
> output.writeFieldEnd()
> }
> if (null != this.finish) {
> output.writeFieldBegin('finish', Thrift.Type.STRING, 2)
> output.writeString(this.finish)
> output.writeFieldEnd()
> }
> if (null != this.reversed) {
> output.writeFieldBegin('reversed', Thrift.Type.BOOL, 3)
> output.writeBool(this.reversed)
> output.writeFieldEnd()
> }
> if (null != this.count) {
> output.writeFieldBegin('count', Thrift.Type.I32, 4)
> output.writeI32(this.count)
> output.writeFieldEnd()
> }
> output.writeFieldStop()
> output.writeStructEnd()
> return
> }
> {code}
> null is also not be completely correct, the solution would be:
> {code}
> ...
> if (undefined !== this.reversed)
> ...
> {code}
> Unless this change was intentional and breaks things because cassandra is
> perhaps using an old thrift version?
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira