Make `GenericType<T>` not implement `java.lang.reflect.Type`
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 35/100
Línea de trabajo
Localiza GenericType e inspecciona sus llamadores y pruebas existentes, especialmente el comportamiento que depende de que sea un java.lang.reflect.Type. Revisa la discusión en #73 y las cuestiones de compatibilidad del issue antes de cambiar la API pública. Se considera terminado cuando GenericType ya no implementa Type, mientras que su comportamiento como contenedor de tipos y las pruebas afectadas siguen siendo correctos.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
In the same vein as #73, probably GenericType should not implement java.lang.reflect.Type. It's not really a "type" itself—it's a type holder.
I can appreciated that the original conception was to have GenericType be a "type" representing a "type with generics" (sort of like an improved ParameterizedType). But in the larger scheme of things and in hindsight, it's really just one of many duplicates of the Super Type Token pattern. And to put this in context:
- The original example in Neil Gafter's famous Super Type Tokens does not implement
Type. - Jackson's
TypeReferencedoes not implementType. - Spring's
ParameterizedTypeReferencedoes not implementType. - The Guice
TypeLiteraldoes not implementType. - The GeantyRef fork of gentyref has a
TypeTokenwhich does not implementType. - Guava's
TypeTokendoes not implementType.
Thus ClassMate's GenericType<T> is the only one that implements java.lang.reflect.Type.
The reason I bring this up is that the whole Type system (as you explain so well) is already confusing and awkward; adding one other wrapper that itself pretends to be a Type, in contrast with all the other uses of this pattern, adds even more confusion.
Let me give an illustration of the confusion it can cause. Let's say (following the discussion in #69) that I want to make a general method to convert some "type token" to a Type (so that I can then use Jackson to convert it to a JavaType, etc.). Look closely at this code:
public static Type typeTokenToType(@Nonnull final Object typeToken) {
//super type token (check first, because ClassMate `GenericType<T>` is also a `Type`)
final Type superTypeTokenSuperClass = typeToken.getClass().getGenericSuperclass();
if(superTypeTokenSuperClass instanceof ParameterizedType parameterizedType) {
final Type[] actualTypeArguments = parameterizedType.getActualTypeArguments();
if(actualTypeArguments.length == 1) {
return actualTypeArguments[0];
}
}
//type
if(typeToken instanceof Type) { //types in general, if they are not super type tokens needing "unwrapping", can be returned directly
return (Type)typeToken;
}
throw new IllegalArgumentException("Type token must be an instance of `Class`, or have a super class providing a single generic type argument.");
}
You see the potential bug if the developer weren't paying attention? In a perfect world, I would first test to see if typeToken is a Type, and just return it, because the type token is already a Type (e.g. a Class<?> or a ParameterizedType). Otherwise I would see if it is a "super type token". And that approach would work with all the other super type tokens—except for ClassMate's GenericType<T>, because GenericType<T> claims it is a Type itself already!
The fix for this example is easy (as shown in the method above): just leave the instanceof Type check for last. But it would be more efficient to test for Type up front. More worrisome, I would have had to have noticed before writing the method (I actually didn't at first) that GenericType<T> implements Type, or I would have wound up with such a bug.
Lots of other bugs may crop up. A developer may write a doFoo(Type type) method, assuming the type has already been "unwrapped", and someone could send it a GenericType<T>, forgetting to unwrap/extract the Type first. I could see this happening all over the place.
At the end of the day this isn't a blocker, and it's certainly not a critical bug. And if you don't agree with me, and you see value in having GenericType<T> implement Type, that's fine. Nevertheless I thought I'd document what I see as an issue so that you can think about it. Cheers!
- Lenguaje dominante
- Java
- Estrellas
- 266
- Forks
- 47
- Merge medio
- 1 h 42 min
- PR fusionados (30 d)
- 1
Guía de contribución
No hay ninguna guía de contribución indexada para este repositorio
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de FasterXML/java-classmate
-
Dificultad 5/5 Más de una semana Aptitud para principiantes 25/100
FasterXML/java-classmate#111 · 10 comentarios ·
-
Dificultad 5/5 Más de una semana Aptitud para principiantes 20/100
FasterXML/java-classmate#81 · 1 comentario ·
-
Dificultad 5/5 Más de una semana Aptitud para principiantes 20/100
FasterXML/java-classmate#72 · 3 comentarios ·
-
Dificultad 4/5 3-5 días Aptitud para principiantes 35/100
FasterXML/java-classmate#69 · 22 comentarios ·
-
Dificultad 4/5 3-5 días Aptitud para principiantes 35/100
FasterXML/java-classmate#57 · 1 comentario ·
Todos los issues de FasterXML/java-classmate
Issues similares
-
awaiting triage bug Causes friction Hop Gui P1 P2 Transforms
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
apache/flink-agents#1152 ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
jenkinsci/blueocean-plugin#5417 ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
objectionary/eo-graphs#75 ·