Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

特定场景下报java.lang.ClassCastException #886

Closed
samyge opened this issue Jul 5, 2023 · 0 comments
Closed

特定场景下报java.lang.ClassCastException #886

samyge opened this issue Jul 5, 2023 · 0 comments

Comments

@samyge
Copy link
Contributor

samyge commented Jul 5, 2023

问题位于tk.mybatis.mapper.mapperhelper.MapperTemplate.getEntityClass(MappedStatement)函数中的
Class<?> returnType = (Class<?>) t.getActualTypeArguments()[0];

经测试,以下场景会触发

  1. 当泛型信息任然为泛型信息时,如
    public interface MyMapper extends Mapper<Info<?>
    此时t.getActualTypeArguments()[0]的实际类型为:ParameterizedType
  2. 当泛型信息为泛型数组时,如
    interface MyMapper<T> extends Mapper<T>
    此时t.getActualTypeArguments()[0]的实际类型为:TypeVariable
  3. 当泛型信息为泛型数组时,如
    interface MyMapper<T> extends Mapper<T[]>
    此时t.getActualTypeArguments()[0]的实际类型为:GenericArrayType

实际使用中,场景1容易发生,场景2和3相对少见,但根据报出来的异常很难发现问题

@abel533 abel533 closed this as completed in 50d9ebf Jul 6, 2023
abel533 added a commit that referenced this issue Jul 6, 2023
解决Mapper父接口的泛型信息在使用泛型的场景下报ClassCastException的问题,fixed #886
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant