commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Yuhau Lin (JIRA)" <j...@apache.org>
Subject [jira] [Created] (LANG-1190) TypeUtils.isAssignable throws NullPointerException when fromType has type variables and toType generic superclass specifies type variable
Date Mon, 07 Dec 2015 19:40:11 GMT
Yuhau Lin created LANG-1190:
-------------------------------

             Summary: TypeUtils.isAssignable throws NullPointerException when fromType has
type variables and toType generic superclass specifies type variable
                 Key: LANG-1190
                 URL: https://issues.apache.org/jira/browse/LANG-1190
             Project: Commons Lang
          Issue Type: Bug
          Components: lang.reflect.*
    Affects Versions: 3.4
            Reporter: Yuhau Lin


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));
    }
}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message