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

Test may fail due to a different order of fields returned by reflection API

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 3.8, 3.9, 3.8.1
    • 3.10
    • lang.builder.*
    • None

    Description

      Tests in HashCodeBuilderTest depends on HashCodeBuilder.reflectionHashCode. The logic of reflectionHashCode appends the fields returned by java.lang.Class.getDeclaredFields. The order of fields being appended will affect the calculated HashCode.

      However, java.lang.Class.getDeclaredFields does not guarantee any specific order and thus, test can fail if the order is different, (i.e., it generates a different hash code). "The elements in the returned array are not sorted and are not in any particular order" (reference: https://docs.oracle.com/javase/8/docs/api/java/lang/Class.html#getDeclaredMethods--)

       

      This affects HashCodeBuilderTest.testReflectionHashCodeExcludeFields and HashCodeBuilderTest.testReflectionHierarchyHashCode as they depend on the order of fields returned by the api. 

       

       

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              contextshuffling contextshuffling
              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 - 0.5h
                  0.5h