You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Pascal Schumacher (JIRA)" <ji...@apache.org> on 2016/05/29 15:45:12 UTC

[jira] [Updated] (LANG-1190) TypeUtils.isAssignable throws NullPointerException when fromType has type variables and toType generic superclass specifies type variable

     [ https://issues.apache.org/jira/browse/LANG-1190?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Pascal Schumacher updated LANG-1190:
------------------------------------
    Description: 
{code:java}
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));
    }
}
{code}

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


> 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
>
> {code:java}
> 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));
>     }
> }
> {code}



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