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

TypeUtilsTest contains incorrect type assignability assertion due to lost/skipped type variable information during the decision process

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 3.1
    • 3.2
    • lang.reflect.*
    • None

    Description

      TypeUtilsTest originally contained the following under #testIsAssignable():

      Assert.assertTrue("WRONG!", TypeUtils.isAssignable(dingType, disType));
      

      For background:

      public interface This<K, V> {
      }
      
      public class Other<T> implements This<String, T> {
      }
      
      public class Thing<Q> extends Other<B> {
      }
      

      <B> refers to a type parameter on the TypeUtilsTest class itself.
      disType and dingType refer to the generic types of the following fields, respectively:

      public This<String, String> dis;
      public Thing ding;
      

      Thus the assertion in question declares that type Thing is assignable to This<String, String>. If we start at This we can see that the implementing class Other maps its T type parameter to the V type parameter of This. From this point we can proceed down to Thing and see that it maps the B type parameter of the enclosing TypeUtilsTest class to the T type parameter of Other. Thus it is fairly obvious that only a TypeUtilsTest<String>.Thing is assignable to This<String, String>. From this we can determine that the intent of the message in the original test assertion must indeed have been to flag an incorrect assertion. This is the associated bug report.

      Attachments

        Issue Links

          Activity

            People

              mbenson Matthew Jason Benson
              mbenson Matthew Jason Benson
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: