代码覆盖帮助发现BUG
今天无意中又浏览了一下代码覆盖的结果,竟然让我无意中发现了一个用其它方法可能不会发觉的BUG。
代码片断如下:
/**
* This method is performance key point of this framework.
* @see org.mockejb.interceptor.AspectSystem#findInterceptors(java.lang.reflect.Method, java.lang.reflect.Method)
*/
public List findInterceptors(Method proxyMethod, Method targetMethod)
{
List resultList = new ArrayList();
List otherResult = find(proxyMethod, targetMethod, otherAspectList);
resultList.addAll(otherResult);
if (proxyMethod != null)
{
String proxyMethodString = proxyMethod.toString();
String targetMethodString = targetMethod.toString();
List aspect = CacheUtil.getBeanAspects(proxyMethodString + "-" + targetMethodString);
if (aspect != null)
{
resultList.addAll(aspect);//168
}
else
{
if (isARMethod(proxyMethodString, targetMethodString))
{
String beanName = getBeanName(proxyMethodString, targetMethodString);
if (beanName != null)
{
List aspects = (List) beanAspectMap.get(beanName);
if (aspects != null)
{
aspect = find(proxyMethod, targetMethod, aspects);
CacheUtil.putBeanAspects(proxyMethodString, aspect);
resultList.addAll(aspect);
}
}
}
}
}
return resultList;
}
注意标记为168的那一行,那个地方是Cache的功能,但是代码覆盖报告指出它没有被执行过,也就是那个Cache从来没有生效,因为原来的cache的key只是proxyMethod.toString(),后来为了在初始化的时候屏蔽ejbPostCreate的执行加了一些Aspect,但是ejbPostCreate和ejbCreate的proxyMethod是一样的,只是targetMethod不同。
这个BUG只影响性能,所以其它的方法是不可能发现问题的。
作者: Cherami
原载: 代码覆盖帮助发现BUG
版权所有。转载时必须以链接形式注明作者和原始出处及本声明。
日志评价
相关日志
随机日志
添加到网摘
[del.icio.us] [新浪 VIVI] [365key] [YouNote] [博采中心] [Poco] [SOHU狐摘] [天极网摘] [和讯网摘]喜欢这个插件?

该日志只有 1 条评论
发表评论 | RSS订阅 | 反向链接