Program: 138560
Project: 138560
Buggy source:
/** 
 * (non-Javadoc)
 * @see org.talend.dq.writer.AElementPersistance#addDependencies(orgomg.cwm.objectmodel.core.ModelElement)
 */
@Override public void addDependencies(ModelElement element){
  Analysis analysis=(Analysis)element;
  List<IndicatorDefinition> udis=AnalysisHelper.getUserDefinedIndicators(analysis);
  try {
    for (    IndicatorDefinition udi : udis) {
      if (udi == null) {
        continue;
      }
      InternalEObject iudi=(InternalEObject)udi;
      if (!iudi.eIsProxy()) {
        TypedReturnCode<Dependency> dependencyReturn=DependenciesHandler.getInstance().setDependencyOn(analysis,udi);
        if (dependencyReturn.isOk()) {
          TDQItem udiItem=(TDQItem)RepositoryNodeHelper.recursiveFind(udi).getObject().getProperty().getItem();
          if (udiItem instanceof TDQIndicatorDefinitionItem) {
            ((TDQIndicatorDefinitionItem)udiItem).setIndicatorDefinition(udi);
          }
 else           if (udiItem instanceof TDQBusinessRuleItem) {
            ((TDQBusinessRuleItem)udiItem).setDqrule((DQRule)udi);
          }
          ProxyRepositoryFactory.getInstance().getRepositoryFactoryFromProvider().getResourceManager().saveResource(udi.eResource());
        }
      }
    }
    List<Pattern> patterns=AnalysisHelper.getPatterns(analysis);
    for (    Pattern pattern : patterns) {
      InternalEObject iptn=(InternalEObject)pattern;
      if (!iptn.eIsProxy()) {
        TypedReturnCode<Dependency> dependencyReturn=DependenciesHandler.getInstance().setDependencyOn(analysis,pattern);
        if (dependencyReturn.isOk()) {
          TDQPatternItem patternItem=(TDQPatternItem)RepositoryNodeHelper.recursiveFind(pattern).getObject().getProperty().getItem();
          patternItem.setPattern(pattern);
          ProxyRepositoryFactory.getInstance().getRepositoryFactoryFromProvider().getResourceManager().saveResource(pattern.eResource());
        }
      }
    }
  }
 catch (  PersistenceException e) {
    e.printStackTrace();
  }
}

Fixed version (ground truth):
/** 
 * (non-Javadoc)
 * @see org.talend.dq.writer.AElementPersistance#addDependencies(orgomg.cwm.objectmodel.core.ModelElement)
 */
@Override public void addDependencies(ModelElement element){
  Analysis analysis=(Analysis)element;
  List<IndicatorDefinition> udis=AnalysisHelper.getUserDefinedIndicators(analysis);
  try {
    for (    IndicatorDefinition udi : udis) {
      if (udi == null) {
        continue;
      }
      InternalEObject iudi=(InternalEObject)udi;
      if (!iudi.eIsProxy()) {
        TypedReturnCode<Dependency> dependencyReturn=DependenciesHandler.getInstance().setDependencyOn(analysis,udi);
        if (dependencyReturn.isOk()) {
          RepositoryNode repositoryNode=RepositoryNodeHelper.recursiveFind(udi);
          if (repositoryNode != null) {
            TDQItem udiItem=(TDQItem)repositoryNode.getObject().getProperty().getItem();
            if (udiItem instanceof TDQIndicatorDefinitionItem) {
              ((TDQIndicatorDefinitionItem)udiItem).setIndicatorDefinition(udi);
            }
 else             if (udiItem instanceof TDQBusinessRuleItem) {
              ((TDQBusinessRuleItem)udiItem).setDqrule((DQRule)udi);
            }
          }
          ProxyRepositoryFactory.getInstance().getRepositoryFactoryFromProvider().getResourceManager().saveResource(udi.eResource());
        }
      }
    }
    List<Pattern> patterns=AnalysisHelper.getPatterns(analysis);
    for (    Pattern pattern : patterns) {
      InternalEObject iptn=(InternalEObject)pattern;
      if (!iptn.eIsProxy()) {
        TypedReturnCode<Dependency> dependencyReturn=DependenciesHandler.getInstance().setDependencyOn(analysis,pattern);
        if (dependencyReturn.isOk()) {
          RepositoryNode repositoryNode=RepositoryNodeHelper.recursiveFind(pattern);
          if (repositoryNode != null) {
            TDQPatternItem patternItem=(TDQPatternItem)repositoryNode.getObject().getProperty().getItem();
            patternItem.setPattern(pattern);
          }
          ProxyRepositoryFactory.getInstance().getRepositoryFactoryFromProvider().getResourceManager().saveResource(pattern.eResource());
        }
      }
    }
  }
 catch (  PersistenceException e) {
    e.printStackTrace();
  }
}