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

TypeUtils.ParameterizedType#equals doesn't work with wildcard types

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 3.3.2, 3.4
    • 3.5
    • lang.reflect.*
    • None

    Description

      There is a bug in TypeUtils.equals(WilcardType, Type). It returns true if the other type is not a WildcardType, it should return false. See TypeUtils@1629 for v3.3.2 and TypeUtils@791 for v3.4

      Bug can be seen with the following test:

      @Test
          public void shouldHandleEqualityOfParameterizedTypesWithWildcards() throws Exception {
              // Given:
              class SomeType {
                  Collection<?> field;
              }
      
              final ParameterizedType wildcardCollectionType = (ParameterizedType) SomeType.class.getDeclaredField("field").getGenericType();
              final WildcardType wildcard = (WildcardType) wildcardCollectionType.getActualTypeArguments()[0];
              final ParameterizedType ptWithWildcard = TypeUtils.parameterize(Collection.class, wildcard);
              final ParameterizedType otherPt = TypeUtils.parameterize(Collection.class, String.class);
      
              // Then:
              assertThat(otherPt, is(not(equalTo(ptWithWildcard))));  // Passes
              assertThat(ptWithWildcard, is(not(equalTo(otherPt))));  // Fails
          }
      

      Attachments

        Activity

          People

            britter Benedikt Ritter
            BigAndy Andy Coates
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: