Skip to content

Commit

Permalink
Fixed API change of the generics reflection API.
Browse files Browse the repository at this point in the history
  • Loading branch information
raphw committed Jul 14, 2015
1 parent e76fa0b commit 808f503
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
Expand Up @@ -1013,7 +1013,9 @@ abstract class ForGenericArray implements GenericTypeDescription {

@Override
public Sort getSort() {
return Sort.GENERIC_ARRAY;
return getComponentType().getSort().isNonGeneric()
? Sort.NON_GENERIC
: Sort.GENERIC_ARRAY;
}

@Override
Expand Down Expand Up @@ -1185,14 +1187,6 @@ public GenericTypeDescription getComponentType() {
? componentType
: new Latent(componentType, arity - 1);
}

@Override
public Sort getSort() {
// This instance can equally represent a raw generic array.
return componentType.getSort().isNonGeneric()
? Sort.NON_GENERIC
: Sort.GENERIC_ARRAY;
}
}
}

Expand Down
@@ -1,6 +1,7 @@
package net.bytebuddy.dynamic.scaffold.subclass;

import net.bytebuddy.ByteBuddy;
import net.bytebuddy.ClassFileVersion;
import net.bytebuddy.description.annotation.AnnotationDescription;
import net.bytebuddy.description.modifier.Visibility;
import net.bytebuddy.description.type.PackageDescription;
Expand All @@ -24,10 +25,7 @@
import java.lang.annotation.Annotation;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.lang.reflect.*;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -335,7 +333,14 @@ public void testGenericType() throws Exception {
assertThat(foo.getTypeParameters()[1].getBounds()[0], is((Type) Exception.class));
assertThat(foo.getGenericReturnType(), instanceOf(ParameterizedType.class));
assertThat(((ParameterizedType) foo.getGenericReturnType()).getActualTypeArguments().length, is(1));
assertThat(((ParameterizedType) foo.getGenericReturnType()).getActualTypeArguments()[0], is((Type) String[].class));
Type parameterType = ((ParameterizedType) foo.getGenericReturnType()).getActualTypeArguments()[0];
// Before Java 7, non-generic array types returned from methods of the generic reflection API returned generic arrays.
if (ClassFileVersion.forCurrentJavaVersion().compareTo(ClassFileVersion.JAVA_V7) < 0) {
assertThat(parameterType, instanceOf(GenericArrayType.class));
assertThat(((GenericArrayType) parameterType).getGenericComponentType(), is((Type) String.class));
} else {
assertThat(parameterType, is((Type) String[].class));
}
assertThat(foo.getGenericParameterTypes().length, is(1));
assertThat(foo.getGenericParameterTypes()[0], is((Type) foo.getTypeParameters()[0]));
assertThat(foo.getGenericExceptionTypes().length, is(1));
Expand Down

0 comments on commit 808f503

Please sign in to comment.