Program: 63427
Project: 63427
Buggy source:
protected Response findAttributeInternal(String version,String persistenceUnit,String type,String id,String attribute,HttpHeaders headers,UriInfo uriInfo){
  JPARSLogger.entering(CLASS_NAME,"String_Node_Str",new Object[]{"String_Node_Str",version,persistenceUnit,type,id,attribute,uriInfo.getRequestUri().toASCIIString()});
  EntityManager em=null;
  try {
    PersistenceContext context=getPersistenceContext(persistenceUnit,type,uriInfo.getBaseUri(),version,null);
    Object entityId=IdHelper.buildId(context,type,id);
    em=context.getEmf().createEntityManager(getMatrixParameters(uriInfo,persistenceUnit));
    Object entity=em.find(context.getClass(type),entityId,getQueryParameters(uriInfo));
    DatabaseSession serverSession=context.getServerSession();
    ClassDescriptor descriptor=serverSession.getClassDescriptor(context.getClass(type));
    if (descriptor == null) {
      throw JPARSException.classOrClassDescriptorCouldNotBeFoundForEntity(type,persistenceUnit);
    }
    DatabaseMapping attributeMapping=descriptor.getMappingForAttributeName(attribute);
    if ((attributeMapping == null) || (entity == null)) {
      throw JPARSException.databaseMappingCouldNotBeFoundForEntityAttribute(attribute,type,id,persistenceUnit);
    }
    if (!attributeMapping.isCollectionMapping()) {
      Object result=attributeMapping.getRealAttributeValueFromAttribute(attributeMapping.getAttributeValueFromObject(entity),entity,(AbstractSession)serverSession);
      if (result == null) {
        JPARSLogger.error("String_Node_Str",new Object[]{attribute,type,id,persistenceUnit});
        throw JPARSException.attributeCouldNotBeFoundForEntity(attribute,type,id,persistenceUnit);
      }
      final FeatureResponseBuilder responseBuilder=context.getSupportedFeatureSet().getResponseBuilder(Feature.NO_PAGING);
      return findAttributeResponse(context,attribute,type,id,persistenceUnit,result,getQueryParameters(uriInfo),headers,uriInfo,responseBuilder);
    }
    ReadQuery query=(ReadQuery)((((ForeignReferenceMapping)attributeMapping).getSelectionQuery()).clone());
    if (query == null) {
      throw JPARSException.selectionQueryForAttributeCouldNotBeFoundForEntity(attribute,type,id,persistenceUnit);
    }
    final FeatureSet featureSet=context.getSupportedFeatureSet();
    final AbstractSession clientSession=context.getClientSession(em);
    if (featureSet.isSupported(Feature.PAGING)) {
      final PageableFieldValidator validator=new PageableFieldValidator(entity.getClass(),attribute,uriInfo);
      if (validator.isFeatureApplicable()) {
        query.setMaxRows(validator.getLimit() + validator.getOffset());
        query.setFirstResult(validator.getOffset());
        final Map<String,Object> queryParams=getQueryParameters(uriInfo);
        queryParams.put(QueryParameters.JPARS_PAGING_LIMIT,String.valueOf(validator.getLimit()));
        queryParams.put(QueryParameters.JPARS_PAGING_OFFSET,String.valueOf(validator.getOffset()));
        checkOrderBy(query);
        final Object result=clientSession.executeQuery(query,descriptor.getObjectBuilder().buildRow(entity,clientSession,WriteType.INSERT));
        final FeatureResponseBuilder responseBuilder=context.getSupportedFeatureSet().getResponseBuilder(Feature.PAGING);
        return findAttributeResponse(context,attribute,type,id,persistenceUnit,result,queryParams,headers,uriInfo,responseBuilder);
      }
    }
    final Object result=clientSession.executeQuery(query,descriptor.getObjectBuilder().buildRow(entity,clientSession,WriteType.INSERT));
    final FeatureResponseBuilder responseBuilder=context.getSupportedFeatureSet().getResponseBuilder(Feature.NO_PAGING);
    return findAttributeResponse(context,attribute,type,id,persistenceUnit,result,getQueryParameters(uriInfo),headers,uriInfo,responseBuilder);
  }
 catch (  Exception ex) {
    throw JPARSException.exceptionOccurred(ex);
  }
 finally {
    if (em != null) {
      if (em.isOpen()) {
        em.close();
      }
    }
  }
}

Fixed version (ground truth):
protected Response findAttributeInternal(String version,String persistenceUnit,String type,String id,String attribute,HttpHeaders headers,UriInfo uriInfo){
  JPARSLogger.entering(CLASS_NAME,"String_Node_Str",new Object[]{"String_Node_Str",version,persistenceUnit,type,id,attribute,uriInfo.getRequestUri().toASCIIString()});
  EntityManager em=null;
  try {
    PersistenceContext context=getPersistenceContext(persistenceUnit,type,uriInfo.getBaseUri(),version,null);
    Object entityId=IdHelper.buildId(context,type,id);
    em=context.getEmf().createEntityManager(getMatrixParameters(uriInfo,persistenceUnit));
    Object entity=em.find(context.getClass(type),entityId,getQueryParameters(uriInfo));
    DatabaseSession serverSession=context.getServerSession();
    ClassDescriptor descriptor=serverSession.getClassDescriptor(context.getClass(type));
    if (descriptor == null) {
      throw JPARSException.classOrClassDescriptorCouldNotBeFoundForEntity(type,persistenceUnit);
    }
    DatabaseMapping attributeMapping=descriptor.getMappingForAttributeName(attribute);
    if ((attributeMapping == null) || (entity == null)) {
      throw JPARSException.databaseMappingCouldNotBeFoundForEntityAttribute(attribute,type,id,persistenceUnit);
    }
    if (!attributeMapping.isCollectionMapping()) {
      Object result=attributeMapping.getRealAttributeValueFromAttribute(attributeMapping.getAttributeValueFromObject(entity),entity,(AbstractSession)serverSession);
      if (result == null) {
        JPARSLogger.error("String_Node_Str",new Object[]{attribute,type,id,persistenceUnit});
        throw JPARSException.attributeCouldNotBeFoundForEntity(attribute,type,id,persistenceUnit);
      }
      final FeatureResponseBuilder responseBuilder=context.getSupportedFeatureSet().getResponseBuilder(Feature.NO_PAGING);
      return findAttributeResponse(context,attribute,type,id,persistenceUnit,result,getQueryParameters(uriInfo),headers,uriInfo,responseBuilder);
    }
    ReadQuery query=(ReadQuery)((((ForeignReferenceMapping)attributeMapping).getSelectionQuery()).clone());
    if (query == null) {
      throw JPARSException.selectionQueryForAttributeCouldNotBeFoundForEntity(attribute,type,id,persistenceUnit);
    }
    final FeatureSet featureSet=context.getSupportedFeatureSet();
    final AbstractSession clientSession=context.getClientSession(em);
    if (featureSet.isSupported(Feature.PAGING)) {
      final PageableFieldValidator validator=new PageableFieldValidator(entity.getClass(),attribute,uriInfo);
      if (validator.isFeatureApplicable()) {
        query.setMaxRows(validator.getLimit() + validator.getOffset() + 1);
        query.setFirstResult(validator.getOffset());
        final Map<String,Object> queryParams=getQueryParameters(uriInfo);
        queryParams.put(QueryParameters.JPARS_PAGING_LIMIT,String.valueOf(validator.getLimit()));
        queryParams.put(QueryParameters.JPARS_PAGING_OFFSET,String.valueOf(validator.getOffset()));
        checkOrderBy(query);
        final Object result=clientSession.executeQuery(query,descriptor.getObjectBuilder().buildRow(entity,clientSession,WriteType.INSERT));
        final FeatureResponseBuilder responseBuilder=context.getSupportedFeatureSet().getResponseBuilder(Feature.PAGING);
        return findAttributeResponse(context,attribute,type,id,persistenceUnit,result,queryParams,headers,uriInfo,responseBuilder);
      }
    }
    final Object result=clientSession.executeQuery(query,descriptor.getObjectBuilder().buildRow(entity,clientSession,WriteType.INSERT));
    final FeatureResponseBuilder responseBuilder=context.getSupportedFeatureSet().getResponseBuilder(Feature.NO_PAGING);
    return findAttributeResponse(context,attribute,type,id,persistenceUnit,result,getQueryParameters(uriInfo),headers,uriInfo,responseBuilder);
  }
 catch (  Exception ex) {
    throw JPARSException.exceptionOccurred(ex);
  }
 finally {
    if (em != null) {
      if (em.isOpen()) {
        em.close();
      }
    }
  }
}