leangen / geantyref

Advanced generic type reflection library with support for working with AnnotatedTypes (for Java 8+)
Apache License 2.0
99 stars 15 forks source link

Unexpected exception when erasing method return type from a wildcard generic class #12

Closed stevenschlansker closed 2 years ago

stevenschlansker commented 2 years ago

Hi @kaqqao , thank you again for this great library. I think I might have found a bug:

@Test
public void testErase() throws Exception {
    GenericTypeReflector.erase(
            GenericTypeReflector.getExactReturnType(
                    E2.class.getMethod("getVal"),
                    GenericTypeReflector.addWildcardParameters(E2.class)));
}

public static class E2<T extends String> {
    private final T val;
    E2(final T val) {
        this.val = val;
    }
    public T getVal() {
        return val;
    }
}

Expected result: String.class Actual result: RuntimeException

java.lang.RuntimeException: not supported: class io.leangen.geantyref.CaptureTypeImpl
    at io.leangen.geantyref.GenericTypeReflector.erase(GenericTypeReflector.java:87)
    at org.jdbi.v3.core.mapper.TestEnums.testErase(TestEnums.java:111)
kaqqao commented 2 years ago

Thanks! Fixed and released v1.3.12 just now. erase now supports CaptureType in the same style as WildcardType.

stevenschlansker commented 2 years ago

Thanks for the fix! :rocket: