今天无意中又浏览了一下代码覆盖的结果,竟然让我无意中发现了一个用其它方法可能不会发觉的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只影响性能,所以其它的方法是不可能发现问题的。

(Visited 149 times, 1 visits today)