Program: 145643
Project: 145643
Buggy source:
protected ActualCacheEntry<SqlQuery> loadQuery(String aAppElementId) throws ParserConfigurationException, Exception {
  if (aAppElementId == null) {
    throw new NullPointerException(CANT_LOAD_NULL_MSG);
  }
  Logger.getLogger(this.getClass().getName()).finer(String.format(LOADING_QUERY_MSG,aAppElementId));
  ApplicationElement appElement=client.getAppCache().get(aAppElementId);
  if (appElement == null && SUBQUERY_LINK_PATTERN.matcher(aAppElementId).matches()) {
    aAppElementId=aAppElementId.substring(1);
    appElement=client.getAppCache().get(aAppElementId);
  }
  if (appElement != null) {
    Document queryDom=appElement.getContent();
    if (queryDom != null) {
      QueryDocument queryDoc=XmlDom2QueryDocument.transform(client,aAppElementId,queryDom);
      QueryModel model=queryDoc.getModel();
      SqlQuery query=queryDoc.getQuery();
      putRolesMutatables(query);
      List<StoredFieldMetadata> additionalFieldsMetadata=queryDoc.getAdditionalFieldsMetadata();
      String sqlText=query.getSqlText();
      if (sqlText != null && !sqlText.isEmpty()) {
        if (query.getFullSqlText() != null && !query.getFullSqlText().isEmpty()) {
          sqlText=query.getFullSqlText();
        }
        try {
          try {
            String compiledSqlText=compileSubqueries(sqlText,model);
            putTableFieldsMetadata(query);
            putStoredTableFieldsMetadata(query,additionalFieldsMetadata);
            putParametersMetadata(query,model);
            query.setSqlText(compiledSqlText);
          }
 catch (          Exception ex) {
            Fields fields=new Fields();
            Field fMd=new Field(DUMMY_FIELD_NAME,ex.getMessage());
            fields.add(fMd);
            query.setFields(fields);
          }
        }
  finally {
          query.setTitle(appElement.getName());
          query.getFields().setTableDescription(query.getTitle());
        }
      }
      return new ActualCacheEntry<>(query,appElement.getTxtContentLength(),appElement.getTxtCrc32());
    }
 else {
      SqlQuery result=new SqlQuery(client);
      Fields fields=new Fields();
      Field fMd=new Field(DUMMY_FIELD_NAME,CONTENT_EMPTY_MSG);
      fields.add(fMd);
      result.setFields(fields);
      return new ActualCacheEntry<>(result,0,0);
    }
  }
 else {
    SqlQuery result=dynamicQueries.get(aAppElementId);
    if (result == null) {
      result=new SqlQuery(client);
      Fields fields=new Fields();
      Field fMd=new Field(DUMMY_FIELD_NAME,ABSENT_QUERY_MSG);
      fields.add(fMd);
      result.setFields(fields);
    }
    return new ActualCacheEntry<>(result,0,0);
  }
}

Fixed version (ground truth):
protected ActualCacheEntry<SqlQuery> loadQuery(String aAppElementId) throws ParserConfigurationException, Exception {
  if (aAppElementId == null) {
    throw new NullPointerException(CANT_LOAD_NULL_MSG);
  }
  Logger.getLogger(this.getClass().getName()).finer(String.format(LOADING_QUERY_MSG,aAppElementId));
  ApplicationElement appElement=client.getAppCache().get(aAppElementId);
  if (appElement == null && SUBQUERY_LINK_PATTERN.matcher(aAppElementId).matches()) {
    aAppElementId=aAppElementId.substring(1);
    appElement=client.getAppCache().get(aAppElementId);
  }
  if (appElement != null) {
    Document queryDom=appElement.getContent();
    if (queryDom != null) {
      QueryDocument queryDoc=XmlDom2QueryDocument.transform(client,aAppElementId,queryDom);
      QueryModel model=queryDoc.getModel();
      SqlQuery query=queryDoc.getQuery();
      putRolesMutatables(query);
      List<StoredFieldMetadata> additionalFieldsMetadata=queryDoc.getAdditionalFieldsMetadata();
      String sqlText=query.getSqlText();
      if (sqlText != null && !sqlText.isEmpty()) {
        if (query.getFullSqlText() != null && !query.getFullSqlText().isEmpty()) {
          sqlText=query.getFullSqlText();
        }
        try {
          try {
            String compiledSqlText=compileSubqueries(sqlText,model);
            try {
              putParametersMetadata(query,model);
              if (putTableFieldsMetadata(query)) {
                putStoredTableFieldsMetadata(query,additionalFieldsMetadata);
              }
            }
  finally {
              query.setSqlText(compiledSqlText);
            }
          }
 catch (          Exception ex) {
            Fields fields=new Fields();
            Field fMd=new Field(DUMMY_FIELD_NAME,ex.getMessage());
            fields.add(fMd);
            query.setFields(fields);
          }
        }
  finally {
          query.setTitle(appElement.getName());
          query.getFields().setTableDescription(query.getTitle());
        }
      }
      return new ActualCacheEntry<>(query,appElement.getTxtContentLength(),appElement.getTxtCrc32());
    }
 else {
      SqlQuery result=new SqlQuery(client);
      Fields fields=new Fields();
      Field fMd=new Field(DUMMY_FIELD_NAME,CONTENT_EMPTY_MSG);
      fields.add(fMd);
      result.setFields(fields);
      return new ActualCacheEntry<>(result,0,0);
    }
  }
 else {
    SqlQuery result=dynamicQueries.get(aAppElementId);
    if (result == null) {
      result=new SqlQuery(client);
      Fields fields=new Fields();
      Field fMd=new Field(DUMMY_FIELD_NAME,ABSENT_QUERY_MSG);
      fields.add(fMd);
      result.setFields(fields);
    }
    return new ActualCacheEntry<>(result,0,0);
  }
}