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

Attach filesAttach ScreenshotVotersWatch issueWatchersCreate sub-taskLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 3.4
    • Fix Version/s: 3.5
    • Component/s: lang.reflect.*
    • Labels:
      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

          Activity

            People

            • Assignee:
              pascalschumacher Pascal Schumacher
              Reporter:
              lyuhau Yuhau Lin

              Dates

              • Created:
                Updated:
                Resolved:

                Issue deployment