You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@thrift.apache.org by "Patrick Dunne (JIRA)" <ji...@apache.org> on 2015/03/25 15:24:53 UTC

[jira] [Comment Edited] (THRIFT-2157) generated code would cause ClassCastException

    [ https://issues.apache.org/jira/browse/THRIFT-2157?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14379916#comment-14379916 ] 

Patrick Dunne edited comment on THRIFT-2157 at 3/25/15 2:24 PM:
----------------------------------------------------------------

Yes, but the code generator mistakenly casts to TBase which is incorrect as specified in THRIFT-2988. That is the issue that would be great to have remedied.

Extract from AsyncMethodCallback onError(Exception e):

{code}
if (e instanceof MyCustomException) {
    result.myCustomException = (MyCustomException) e;
    result.setMyCustomExceptionIsSet(true);
    msg = result;
}
else 
{
    msgType = org.apache.thrift.protocol.TMessageType.EXCEPTION;
    // The line below will cause a class cast exception, this line was generated by the thrift library
    msg = (org.apache.thrift.TBase)new org.apache.thrift.TApplicationException(org.apache.thrift.TApplicationException.INTERNAL_ERROR, e.getMessage());
}
{code}


was (Author: hypnopadge):
Yes, but the code generator mistakenly casts to TBase which is incorrect as specified in THRIFT-2988. That is the issue that would be great to have remedied.

Extract from AsyncMethodCallback onError(Exception e):

<code>
if (e instanceof MyCustomException) {
    result.myCustomException = (MyCustomException) e;
    result.setMyCustomExceptionIsSet(true);
    msg = result;
}
else 
{
    msgType = org.apache.thrift.protocol.TMessageType.EXCEPTION;
    // The line below will cause a class cast exception, this line was generated by the thrift library
    msg = (org.apache.thrift.TBase)new org.apache.thrift.TApplicationException(org.apache.thrift.TApplicationException.INTERNAL_ERROR, e.getMessage());
}
</code>

> generated code would cause ClassCastException
> ---------------------------------------------
>
>                 Key: THRIFT-2157
>                 URL: https://issues.apache.org/jira/browse/THRIFT-2157
>             Project: Thrift
>          Issue Type: Bug
>          Components: Java - Compiler
>    Affects Versions: 0.9.1
>            Reporter: Dave Brosius
>            Priority: Trivial
>
> Looking at the thrift generated code for cassandra, i'm seeing
>  msg = (org.apache.thrift.TBase)new org.apache.thrift.TApplicationException(org.apache.thrift.TApplicationException.INTERNAL_ERROR, e.getMessage());
> as seen here
> https://git-wip-us.apache.org/repos/asf?p=cassandra.git;a=blob;f=interface/thrift/gen-java/org/apache/cassandra/thrift/Cassandra.java;h=837acfc0e964249fd62720420e8f1f85d966f1a3;hb=8f202895ab9e17c3d6bd4965924fd5f1ffc27f94#l6095
> i don't see how TApplicationException can be cast to TBase, and so i'd expect a ClassCastException there.



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