google-code-export / nutz

Automatically exported from code.google.com/p/nutz
Apache License 2.0
1 stars 1 forks source link

入口方法中包含数组参数时,启动报错 #417

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
问题产生的条件:
当入口方法中包含数组类型的参数时,启动会报错

@Param("businessMode") String[] businessMode
我的入口方法里有这样的参数,断点到这里就出错了

异常堆栈:
[2011-03-25 14:04:45] [INFO ] - Nutz Version : 1.b.36 
[2011-03-25 14:04:45] [INFO ] - Nutz.Mvc[nutz] is initializing ...
[2011-03-25 14:04:45] [INFO ] - Build URL mapping by 
org.nutz.mvc.impl.UrlMappingImpl@1e965e9 ...
[2011-03-25 14:05:13] [ERROR] - Error happend during start serivce!
java.lang.ClassCastException: 
sun.reflect.generics.reflectiveObjects.GenericArrayTypeImpl cannot be cast to 
java.lang.Class
    at org.nutz.mvc.adaptor.AbstractAdaptor.evalInjector(AbstractAdaptor.java:126)
    at org.nutz.mvc.adaptor.AbstractAdaptor.init(AbstractAdaptor.java:75)
    at org.nutz.mvc.impl.processor.AdaptorProcessor.evalHttpAdaptor(AdaptorProcessor.java:40)
    at org.nutz.mvc.impl.processor.AdaptorProcessor.init(AdaptorProcessor.java:23)
    at org.nutz.mvc.impl.NutActionChainMaker.eval(NutActionChainMaker.java:29)
    at org.nutz.mvc.impl.UrlMappingImpl.add(UrlMappingImpl.java:28)
    at org.nutz.mvc.impl.NutLoading.evalUrlMapping(NutLoading.java:166)
    at org.nutz.mvc.impl.NutLoading.load(NutLoading.java:89)
    at org.nutz.mvc.ActionHandler.<init>(ActionHandler.java:17)
    at org.nutz.mvc.NutFilter.init(NutFilter.java:41)

Original issue reported on code.google.com by happyday...@gmail.com on 25 Mar 2011 at 6:10

GoogleCodeExporter commented 9 years ago
能够重现,要这样重现:
public void testArrayArgs(@Param("names") List<String>[] names)

Original comment by wendal1985@gmail.com on 25 Mar 2011 at 6:31

GoogleCodeExporter commented 9 years ago
Fix in r1927

但最好找多几个小白鼠测试一下

Original comment by wendal1985@gmail.com on 25 Mar 2011 at 7:28

GoogleCodeExporter commented 9 years ago
我用 JUnit 重现了这个问题,参看 r1934 + r1935

问题出在 AbstractAdaptor.init(Method method) 函数的 52 行:

      Type[] types = method.getGenericParameterTypes();

原因是:

如果入口函数:public String f_B(@Param("ids") long[] ids) {
      那么 types 就是 Class<T>(long[])
      结果很正常

如果入口函数:public List<String> f_A(@Param("ids") long[] ids) {
      那么 types 就是 GenericArrayTypeImpl 
      所以在 134 行 Class<?> clazz = Lang.getTypeClass(type); 执行的时候, 只能得到一个 long 而不是 long[]

这里我非常的奇怪,为啥 Lang.getTypeClass 遇到 GenericArrayTypeImpl 
的时候,要取内部元素的类型? 这不是明显错的吗?

Original comment by zozoh...@gmail.com on 26 Mar 2011 at 5:41

GoogleCodeExporter commented 9 years ago
This issue was closed by revision r1936.

Original comment by zozoh...@gmail.com on 26 Mar 2011 at 5:46

GoogleCodeExporter commented 9 years ago

Original comment by zozoh...@gmail.com on 26 Mar 2011 at 5:52