Uploaded image for project: 'Thrift'
  1. Thrift
  2. THRIFT-3870

Impossible cast bugs in generated for java code

    XMLWordPrintableJSON

    Details

      Description

      Generated by thrift compiler Java code contains "Impossible cast" bugs.
      Affected generated java-code only for service definitions.

      For example:

      myThriftService.thrift
      service MyThriftService {
          i32 multiplyNumbers(1:i32 multiplier, 2:i32 multiplicand);
      }
      

      From cmd run:

      thrift-0.9.3.exe -r --gen java myThriftService.thrift
      

      Generated java code:

      gen-java\MyThriftService.java
      ...
      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());
                              }
                  ..
                } 
                ...
              }
            ...
          }
          ...
      }
      

      Problem is that org.apache.thrift.TApplicationException does not implement org.apache.thrift.TBase.

      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)

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              nme nikit
            • Votes:
              1 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated: