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

TypeUtils.isAssignable throws NullPointerException when fromType has type variables and toType generic superclass specifies type variable

    XMLWordPrintableJSON

Details

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

    Description

      import static org.apache.commons.lang3.reflect.TypeUtils.*;
      
      import java.lang.reflect.InvocationTargetException;
      import java.lang.reflect.Type;
      import java.util.ArrayList;
      
      public class Demonstration {
      
          public static <U> Iterable<U> someMethod() { return null; }
          
          public static class WorkingClass extends ArrayList { }
          public static class FailingClass extends ArrayList<Object> { }
          
          
          public static void main(String[] args) throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
              Type fromType = Demonstration.class.getDeclaredMethod("someMethod").getGenericReturnType();
              Type workingToType = wildcardType().withLowerBounds(WorkingClass.class).build();
              Type failingToType = wildcardType().withLowerBounds(FailingClass.class).build();
              
              System.out.println(fromType);
              System.out.println(workingToType);
              System.out.println(failingToType);
              
              System.out.println(isAssignable(fromType, workingToType));
              System.out.println(isAssignable(fromType, failingToType));
          }
      }
      

      Attachments

        Issue Links

          Activity

            People

              pascalschumacher Pascal Schumacher
              lyuhau Yuhau Lin
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: