HBase
  1. HBase
  2. HBASE-9589

Bytes#LexicographicalComparerHolder#UnsafeComparer#compareTo() has dead code

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Minor Minor
    • Resolution: Not a Problem
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None

      Description

      Starting with line 1177:

                if (diff != 0) {
                  if (!littleEndian) {
                    return lessThanUnsigned(lw, rw) ? -1 : 1;
                  }
      
                  // Use binary search
                  int n = 0;
                  int y;
                  int x = (int) diff;
                  if (x == 0) {
                    x = (int) (diff >>> 32);
      

      The value of "x" cannot be equal to 0.

        Activity

        Hide
        Gustavo Anatoly added a comment -

        Hi, Ted.

        I was debugging the code above and saw that diff casting to integer, returns zero to X and stepping into to the conditional block, where the X value is changed, and running TestBytes#testSplit2 to debug, we have:

        long lw = 4697024864412005480
        long rw = 8804307724573897832
        long diff = lw ^ rw 
        diff = 4251398048237748224
        
        // The cast below, return 0
        int x = (int) diff;
        
        // Step into
        if (x == 0) {
            x = (int) (diff >>> 32);
            n = 32;
        }
        
        Now, x = 989855744
        

        Ted, forgive me if my understanding it's wrong. There are other reason that I can't see, the causes why X cannot be zero?

        Show
        Gustavo Anatoly added a comment - Hi, Ted. I was debugging the code above and saw that diff casting to integer, returns zero to X and stepping into to the conditional block, where the X value is changed, and running TestBytes#testSplit2 to debug, we have: long lw = 4697024864412005480 long rw = 8804307724573897832 long diff = lw ^ rw diff = 4251398048237748224 // The cast below, return 0 int x = ( int ) diff; // Step into if (x == 0) { x = ( int ) (diff >>> 32); n = 32; } Now, x = 989855744 Ted, forgive me if my understanding it's wrong. There are other reason that I can't see, the causes why X cannot be zero?
        Hide
        Ted Yu added a comment -

        x is assigned at line 1185:

                    int x = (int) diff;
        

        At line 1177, we have:

                  if (diff != 0) {
        
        Show
        Ted Yu added a comment - x is assigned at line 1185: int x = ( int ) diff; At line 1177, we have: if (diff != 0) {
        Hide
        Gustavo Anatoly added a comment -

        Ted, sorry for delay to answer.

        At line 1185, when:

        diff > Integer.MAX_VALUE For example on TestBytes

        int x = (int) diff; // x is assigned to zero
        

        But,

        diff < Integer.MAX_VALUE For example on TestLoadTestKVGenerator
        In this case, "if block" is ignored.

        int x = (int) diff; // x is assigned to same value of diff
        

        Therefore, IMHO we need the line 1185.

        Show
        Gustavo Anatoly added a comment - Ted, sorry for delay to answer. At line 1185, when: diff > Integer.MAX_VALUE For example on TestBytes int x = ( int ) diff; // x is assigned to zero But, diff < Integer.MAX_VALUE For example on TestLoadTestKVGenerator In this case, "if block" is ignored. int x = ( int ) diff; // x is assigned to same value of diff Therefore, IMHO we need the line 1185.
        Hide
        Ted Yu added a comment -

        Pardon me for not being clear.
        What I meant was that the body of following if block would not be executed:

                    if (x == 0) {
                      x = (int) (diff >>> 32);
                      n = 32;
                    }
        

        because x wouldn't be 0.

        int x = (int) diff; // x is assigned to zero
        

        Can you confirm whether 0 is assigned to x ?
        In the following example, x is assigned x -2147483647:

            long diff = Integer.MAX_VALUE + 2;
            int x = (int) diff;
        
        Show
        Ted Yu added a comment - Pardon me for not being clear. What I meant was that the body of following if block would not be executed: if (x == 0) { x = ( int ) (diff >>> 32); n = 32; } because x wouldn't be 0. int x = ( int ) diff; // x is assigned to zero Can you confirm whether 0 is assigned to x ? In the following example, x is assigned x -2147483647: long diff = Integer .MAX_VALUE + 2; int x = ( int ) diff;
        Hide
        Ted Yu added a comment -

        When diff is 4251398048237748224, x is assigned 0.

        Closing this issue.

        Show
        Ted Yu added a comment - When diff is 4251398048237748224, x is assigned 0. Closing this issue.
        Hide
        Gustavo Anatoly added a comment -

        Ted, I saw your comment now, sorry. Your example is interesting:

        long diff = Integer.MAX_VALUE + 2;
        int x = (int) diff; // x -2147483647
        

        I did the same example, changing 2 by 1, and really the value is negative. Other interesting point is, if you try assign

         long diff = 4251398048237748224; // Error out of range 

        But, when:

         long max = Long.parseLong("4251398048237748224");
         System.out.println("Max: " + max); // max = 4251398048237748224
         if (max < Long.MAX_VALUE) {
           System.out.println("Less than Long.MAX_VALUE");
         }
         int x = (int) max;
         System.out.println("(int) long: " + x); // x = 0
        

        Interesting

        Thanks for you attention.

        Show
        Gustavo Anatoly added a comment - Ted, I saw your comment now, sorry. Your example is interesting: long diff = Integer .MAX_VALUE + 2; int x = ( int ) diff; // x -2147483647 I did the same example, changing 2 by 1, and really the value is negative. Other interesting point is, if you try assign long diff = 4251398048237748224; // Error out of range But, when: long max = Long .parseLong( "4251398048237748224" ); System .out.println( "Max: " + max); // max = 4251398048237748224 if (max < Long .MAX_VALUE) { System .out.println( "Less than Long .MAX_VALUE" ); } int x = ( int ) max; System .out.println( "( int ) long : " + x); // x = 0 Interesting Thanks for you attention.

          People

          • Assignee:
            Unassigned
            Reporter:
            Ted Yu
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development