提交 4cba3162 编写于 作者: T tony.chenl

DUBBO-425 service没有方法 wrapper报错

git-svn-id: http://code.alibabatech.com/svn/dubbo/trunk@1972 1a56cb94-b969-4eaa-88fa-be21384802f2
上级 da741813
......@@ -215,7 +215,7 @@ public abstract class Wrapper
c1.append(name).append(" w; try{ w = ((").append(name).append(")$1); }catch(Throwable e){ throw new IllegalArgumentException(e); }");
c2.append(name).append(" w; try{ w = ((").append(name).append(")$1); }catch(Throwable e){ throw new IllegalArgumentException(e); }");
c3.append(name).append(" w; try{ w = ((").append(name).append(")$1); }catch(Throwable e){ throw new IllegalArgumentException(e); } try{");
c3.append(name).append(" w; try{ w = ((").append(name).append(")$1); }catch(Throwable e){ throw new IllegalArgumentException(e); }");
Map<String, Class<?>> pts = new HashMap<String, Class<?>>(); // <property name, property types>
Map<String, Method> ms = new LinkedHashMap<String, Method>(); // <method desc, Method instance>
......@@ -237,6 +237,10 @@ public abstract class Wrapper
Method[] methods = c.getMethods();
// get all public method.
boolean hasMethod = hasMethods(methods);
if( hasMethod ){
c3.append(" try{");
}
for( Method m : methods )
{
if( m.getDeclaringClass() == Object.class ) //ignore Object's method.
......@@ -277,9 +281,12 @@ public abstract class Wrapper
dmns.add(mn);
ms.put(ReflectUtils.getDesc(m), m);
}
c3.append(" } catch(Throwable e) { " );
c3.append(" throw new java.lang.reflect.InvocationTargetException(e); " );
c3.append(" }");
if( hasMethod ){
c3.append(" } catch(Throwable e) { " );
c3.append(" throw new java.lang.reflect.InvocationTargetException(e); " );
c3.append(" }");
}
c3.append(" throw new " + NoSuchMethodException.class.getName() + "(\"Not found method \\\"\"+$2+\"\\\" in class " + c.getName() + ".\"); }");
// deal with get/set method.
......@@ -407,4 +414,16 @@ public abstract class Wrapper
{
return pn.length() == 1 || Character.isLowerCase(pn.charAt(1)) ? Character.toLowerCase(pn.charAt(0)) + pn.substring(1) : pn;
}
private static boolean hasMethods(Method[] methods){
if(methods == null || methods.length == 0){
return false;
}
for(Method m : methods){
if(m.getDeclaringClass() != Object.class){
return true;
}
}
return false;
}
}
\ No newline at end of file
......@@ -49,6 +49,11 @@ public class WrapperTest extends TestCase
} catch (NoSuchMethodException expected) {
}
}
//bug: DUBBO-425
public void test_makeEmptyClass() throws Exception {
Wrapper.getWrapper(EmptyServiceImpl.class);
}
public static class Impl0
......@@ -110,4 +115,12 @@ public class WrapperTest extends TestCase
fv = f;
}
}
public static interface EmptyService
{
}
public static class EmptyServiceImpl implements EmptyService
{
}
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册