[
https://issues.apache.org/jira/browse/THRIFT-3870?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
nikit updated THRIFT-3870:
--------------------------
Component/s: Java - Library
Java - Compiler
> Impossible cast bugs in generated for java code
> -----------------------------------------------
>
> Key: THRIFT-3870
> URL: https://issues.apache.org/jira/browse/THRIFT-3870
> Project: Thrift
> Issue Type: Bug
> Components: Java - Compiler, Java - Library
> Affects Versions: 0.9.3
> Environment: windows 7
> [libthrift
> 0.9.3|https://mvnrepository.com/artifact/org.apache.thrift/libthrift/0.9.3]
> [Thrift compiler for Windows
> (thrift-0.9.3.exe)|http://www.apache.org/dyn/closer.cgi?path=/thrift/0.9.3/thrift-0.9.3.exe]
> Reporter: nikit
>
> Generated by thrift compiler Java code contains "Impossible cast" bugs.
> Affected generated java-code only for service definitions.
> For example:
> {code:title=myThriftService.thrift|borderStyle=solid}
> service MyThriftService {
> i32 multiplyNumbers(1:i32 multiplier, 2:i32 multiplicand);
> }
> {code}
> From cmd run:
> {code}
> thrift-0.9.3.exe -r --gen java myThriftService.thrift
> {code}
> Generated java code:
> {code:title=gen-java\\MyThriftService.java|borderStyle=solid}
> ...
> public class MyThriftService {
> ...
> public static class multiplyNumbers<I extends AsyncIface> extends
> org.apache.thrift.AsyncProcessFunction<I, multiplyNumbers_args, Integer> {
> ...
> public AsyncMethodCallback<Integer> getResultHandler(final
> AsyncFrameBuffer fb, final int seqid) {
> final org.apache.thrift.AsyncProcessFunction fcall = this;
> return new AsyncMethodCallback<Integer>() {
> ...
> public void onError(Exception e) {
> ...
> multiplyNumbers_result result = new
> multiplyNumbers_result();
> {
> msgType =
> org.apache.thrift.protocol.TMessageType.EXCEPTION;
> msg = (org.apache.thrift.TBase)new
> org.apache.thrift.TApplicationException(org.apache.thrift.TApplicationException.INTERNAL_ERROR,
> e.getMessage());
> }
> ..
> }
> ...
> }
> ...
> }
> ...
> }
> {code}
> Problem is that org.apache.thrift.TApplicationException does not implement
> org.apache.thrift.TBase.
> {panel:title=Findbugs description}
> Bug: Impossible cast from org.apache.thrift.TApplicationException to
> org.apache.thrift.TBase in
> MyThriftService$AsyncProcessor$multiplyNumbers$1.onError(Exception)
> This cast will always throw a ClassCastException. FindBugs tracks type
> information from instanceof checks, and also uses more precise information
> about the types of values returned from methods and loaded from fields. Thus,
> it may have more precise information that just the declared type of a
> variable, and can use this to determine that a cast will always throw an
> exception at runtime.
> Rank: Scary (9), confidence: High
> Pattern: BC_IMPOSSIBLE_CAST
> Type: BC, Category: CORRECTNESS (Correctness)
> {panel}
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)