Uploaded image for project: 'Kudu'
  1. Kudu
  2. KUDU-2058

Java LocatedTablet implementation has sketchy string comparison

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 1.4.0
    • Fix Version/s: 1.5.0
    • Component/s: client, java
    • Labels:
    • Target Version/s:

      Description

      Findbugs spotted this issue where two strings are compared by identity instead of content:

        /**
         * Return the first occurrence for the given role, or null if there is none.
         */
        private Replica getOneOfRoleOrNull(Role role) {
          for (Replica r : replicas) {
            if (r.getRole() == role.toString()) {
              return r;
            }
          }
          return null;
        }
      

      it's not clear why strings are being used for comparison at all rather than checking enum value equality, which would be both faster and more likely to be correct. It may be that this code works fine despite the sketchiness, though, because the two string objects are likely to be derived from the same enumValue.toString() which returns a constant string object.

        Attachments

          Activity

            People

            • Assignee:
              srisaikumar-inspur Sri Sai Kumar Ravipati
              Reporter:
              tlipcon Todd Lipcon
            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: