Program: 39015
Project: 39015
Buggy source:
/** 
 * 自动获取系统所有资源 需要每一个资源entity继承自BaseResource且对应的service继承BaseResourceService
 * @throws Exception
 */
private void addResourcesAuto() throws Exception {
  List<Class<?>> classes=PackageUtil.getClass("String_Node_Str",true);
  if (classes.isEmpty())   return;
  WebApplicationContext wac=ContextLoader.getCurrentWebApplicationContext();
  List<Resource> resources=resourceRepository.findAll();
  Map<String,Resource> resourceMap=new HashMap<>();
  for (  Resource r : resources) {
    resourceMap.put(r.getResourceId(),r);
  }
  for (  Class c : classes) {
    Class superClass=c.getSuperclass();
    if (superClass == null)     return;
    if (!"String_Node_Str".equals(superClass.getName()))     continue;
    String[] cPackage=c.getName().split("String_Node_Str");
    if (cPackage.length <= 0)     return;
    String serviceName=cPackage[cPackage.length - 1] + "String_Node_Str";
    Class serviceClass=wac.getBean(serviceName).getClass();
    if (serviceClass == null)     return;
    Object serviceObject=serviceClass.newInstance();
    if (serviceObject == null)     return;
    Method serviceFindAllMethod=serviceClass.getMethod("String_Node_Str");
    if (serviceFindAllMethod == null)     return;
    List<Resource> resourceList=(List<Resource>)serviceFindAllMethod.invoke(serviceObject,null);
    for (    Resource r : resourceList) {
      if (resourceMap.containsKey(r.getResourceId())) {
        if (r.getResourceName().equals(resourceMap.get(r.getResourceId())))         continue;
        resourceMap.get(r.getResourceId()).setResourceName(r.getResourceName());
      }
 else {
        resources.add(r);
      }
    }
  }
  resourceRepository.save(resources);
}

Fixed version (ground truth):
/** 
 * 自动获取系统所有资源 需要每一个资源entity继承自BaseResource且对应的service继承BaseResourceService
 * @throws Exception
 */
private void addResourcesAuto() throws Exception {
  List<Class<?>> classes=PackageUtil.getClass("String_Node_Str",true);
  if (classes.isEmpty())   return;
  List<Resource> resources=resourceRepository.findAll();
  Map<String,Resource> resourceMap=new HashMap<>();
  for (  Resource r : resources) {
    resourceMap.put(r.getResourceId(),r);
  }
  String[] beanNames=context.getBeanDefinitionNames();
  for (  String beanName : beanNames) {
    System.out.println("String_Node_Str" + beanName);
  }
  for (  Class c : classes) {
    Class superClass=c.getSuperclass();
    if (superClass == null)     continue;
    if (!"String_Node_Str".equals(superClass.getName()))     continue;
    String[] cPackage=c.getName().split("String_Node_Str");
    if (cPackage.length <= 0)     continue;
    String serviceName=cPackage[cPackage.length - 1] + "String_Node_Str";
    Object objBean=context.getBean(StringUtils.toLowerCaseFirstOne(serviceName));
    Method serviceFindAllMethod=objBean.getClass().getMethod("String_Node_Str");
    if (serviceFindAllMethod == null)     continue;
    List<BaseResource> resourceList=(List<BaseResource>)serviceFindAllMethod.invoke(objBean);
    for (    BaseResource r : resourceList) {
      if (resourceMap.containsKey(r.getResourceId())) {
        if (r.getName().equals(resourceMap.get(r.getResourceId())))         continue;
        resourceMap.get(r.getResourceId()).setResourceName(r.getName());
      }
 else {
        Resource resource=new Resource(r);
        resources.add(resource);
      }
    }
  }
  if (!resources.isEmpty())   resourceRepository.save(resources);
}