0 Replies Latest reply on Dec 13, 2013 11:42 AM by tcunning

    Findbugs issues

    tcunning

      The good news is that a lot of things were fixable.       I'd say the most common thing that findbugs found were the following :

       

      SBSC_USE_STRINGBUFFER_CONCATENATION

        String s = "";
        for (int i = 0; i < field.length; ++i) {
        s = s + field[i];
        }
      

      Findbugs wants you to use a StringBuffer or StringBuilder in this instance and append field[i] rather than create a whole lot of strings.

       

      WMI_WRONG_MAP_ITERATOR

      for (String id : mymap.keySet()) {
           value = mymap.get(id);
           blahblahblah(value);
      }
      

       

      In this instance, findbugs wants us to use an iterator on the entrySet of the map because it is more efficient than rolling through and then doing lookups piecemeal.

       

      The bad news is that there were a number of rules that popped up that I wasn't sure how to deal with and are still out there.        I've gone ahead and provided exceptions for them for now in findbugs-exclude.xml, but I've also logged JIRAs for these so that they don't end up forgotten and balloon into a bigger problem with subsequent commits.     If any of these are something that you think we should just grant block exclusion to, please speak up.

       

      IS2_INCONSISTENT_SYNC

      Findbugs description : http://findbugs.sourceforge.net/bugDescriptions.html#IS2_INCONSISTENT_SYNC

      SwitchYard JIRA : https://issues.jboss.org/browse/SWITCHYARD-1901

       

      Example :

          @Override
          public Context getContext(Message message) {
              if (_message != null && _message == message) {
                  return getContext();
              }
              return message.getContext();
          }
      
      
          @Override
          public Message getMessage() {
              return _message;
          }
      
          @Override
          public synchronized void send(Message message) {
              assertMessageOK(message);
              // Set exchange phase
              if (_phase == null) {
                  _phase = ExchangePhase.IN;
                  initContentType(message);
              } else if (_phase.equals(ExchangePhase.IN)) {
                  _phase = ExchangePhase.OUT;
                  initContentType(message);
                  // set relatesTo header on OUT context
                  Object propertyValue = _message.getContext().getPropertyValue(MESSAGE_ID);
                  message.getContext().setProperty(RELATES_TO, propertyValue)
                      .addLabels(BehaviorLabel.TRANSIENT.label());
              } else {
                  throw RuntimeMessages.MESSAGES.sendMessageNotAllowed(_phase.toString());
              }
              sendInternal(message);
          }
      
          @Override
          public synchronized void sendFault(Message message) {
              assertMessageOK(message);
      
              // You can't send a fault before you send a message
              if (_phase == null) {
                  throw RuntimeMessages.MESSAGES.sendFaultNotAllowed();
              }
              
              _phase = ExchangePhase.OUT;
              _state = ExchangeState.FAULT;
              initFaultContentType();
      
      
              // set relatesTo header on OUT context
              message.getContext().setProperty(RELATES_TO, _message.getContext().getPropertyValue(MESSAGE_ID))
                  .addLabels(BehaviorLabel.TRANSIENT.label());
      
      
              sendInternal(message);
          }
      


      DM_DEFAULT_ENCODING

      Findbugs description : http://findbugs.sourceforge.net/bugDescriptions.html#DM_DEFAULT_ENCODING

      SwitchYard JIRA : https://issues.jboss.org/browse/SWITCHYARD-1903

       

      Example :

       

          public String pull(InputStream stream) throws IOException {
              return pull(new InputStreamReader(stream));
          }
      

       

      EI_EXPOSE_REP / EI_EXPOSE_REP2

      Findbugs description : http://findbugs.sourceforge.net/bugDescriptions.html#EI_EXPOSE_REP

      SwitchYard JIRA : https://issues.jboss.org/browse/SWITCHYARD-1887

       

      Example :

          private Integer[] _ids;
      
          ... 
      
          public Integer[] getIds() {
              return _ids;
          }
      

       

      DP_CREATE_CLASSLOADER_INSIDE_DO_PRIVILEGED

      Findbugs description : http://findbugs.sourceforge.net/bugDescriptions.html#DP_CREATE_CLASSLOADER_INSIDE_DO_PRIVILEGED

      SwitchYard JIRA : https://issues.jboss.org/browse/SWITCHYARD-1902

       

          public static ClassLoader getClassLoader() {
              return new CompoundClassLoader(getClassLoaders());
          }