Uploaded image for project: 'Commons Lang'
  1. Commons Lang
  2. LANG-1615

ArrayUtils contains() and indexOf() fails to handle Float.NaN

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 3.11
    • 3.12.0
    • None

    Description

      The ArrayUtils.contains (float [], Float.NaN) and ArrayUtils.indexOf (float [], Float.NaN) methods do not handle correctly when the array contains Float.NaN. It should return that finds the element, but instead returns -1.

       For example, consider the following: 

      @Test
      public void testContainsFloatNaN() {
       float[] a = new float[] { Float.NEGATIVE_INFINITY, Float.NaN, Float.POSITIVE_INFINITY };
       assertTrue(ArrayUtils.contains(a, Float.POSITIVE_INFINITY));
       assertTrue(ArrayUtils.contains(a, Float.NEGATIVE_INFINITY));
       assertTrue(ArrayUtils.contains(a, Float.NaN)); // Error
      }

       

      And  

      @Test
      public void testIndexOfFloatNaN() {
       float[] array = new float[] { Float.NEGATIVE_INFINITY, Float.NaN,       Float.POSITIVE_INFINITY, Float.NaN }; 
       assertEquals(0, ArrayUtils.indexOf(array, Float.NEGATIVE_INFINITY));
       assertEquals(1, ArrayUtils.indexOf(array, Float.NaN)); // Error
       assertEquals(2, ArrayUtils.indexOf(array, Float.POSITIVE_INFINITY));
      }

       

      Attachments

        Issue Links

          Activity

            People

              ggregory Gary D. Gregory
              arturobernalg Arturo Bernal
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 1h
                  1h