Program: 64354
Project: 64354
Buggy source:
/** 
 * Tests a StoredProcedureQuery that does an update though EM API  This is the same test as above except different retrieval path.
 */
public void testEMCreateStoredProcedureExecuteQuery2(){
  if (supportsStoredProcedures() && getPlatform().isMySQL()) {
    EntityManager em=createEntityManager();
    try {
      String postalCodeTypo="String_Node_Str";
      String postalCodeCorrection="String_Node_Str";
      beginTransaction(em);
      Address address1=new Address();
      address1.setCity("String_Node_Str");
      address1.setPostalCode(postalCodeTypo);
      address1.setProvince("String_Node_Str");
      address1.setStreet("String_Node_Str");
      address1.setCountry("String_Node_Str");
      em.persist(address1);
      Address address2=new Address();
      address2.setCity("String_Node_Str");
      address2.setPostalCode(postalCodeTypo);
      address2.setProvince("String_Node_Str");
      address2.setStreet("String_Node_Str");
      address2.setCountry("String_Node_Str");
      em.persist(address2);
      Address address3=new Address();
      address3.setCity("String_Node_Str");
      address3.setPostalCode(postalCodeCorrection);
      address3.setProvince("String_Node_Str");
      address3.setStreet("String_Node_Str");
      address3.setCountry("String_Node_Str");
      em.persist(address3);
      commitTransaction(em);
      em.clear();
      clearCache();
      StoredProcedureQuery query=em.createStoredProcedureQuery("String_Node_Str",Address.class,Employee.class);
      query.registerStoredProcedureParameter("String_Node_Str",String.class,ParameterMode.IN);
      query.registerStoredProcedureParameter("String_Node_Str",String.class,ParameterMode.IN);
      query.registerStoredProcedureParameter("String_Node_Str",Integer.class,ParameterMode.OUT);
      boolean result=query.setParameter("String_Node_Str",postalCodeCorrection).setParameter("String_Node_Str",postalCodeTypo).execute();
      assertTrue("String_Node_Str",result);
      assertTrue("String_Node_Str",query.hasMoreResults());
      assertTrue("String_Node_Str",query.hasMoreResults());
      assertTrue("String_Node_Str",query.hasMoreResults());
      assertTrue("String_Node_Str",query.hasMoreResults());
      assertTrue("String_Node_Str",query.hasMoreResults());
      assertTrue("String_Node_Str",query.hasMoreResults());
      assertTrue("String_Node_Str",query.hasMoreResults());
      List<Address> addressResults=query.getResultList();
      List<Employee> employeeResults=query.getResultList();
      int numberOfEmployes=employeeResults.size();
      assertFalse("String_Node_Str",query.hasMoreResults());
      assertFalse("String_Node_Str",query.hasMoreResults());
      assertFalse("String_Node_Str",query.hasMoreResults());
      assertFalse("String_Node_Str",query.hasMoreResults());
      assertNull("String_Node_Str",query.getResultList());
      int updateCount=query.getUpdateCount();
      assertTrue("String_Node_Str" + updateCount,updateCount == 2);
      assertTrue("String_Node_Str",query.getUpdateCount() == -1);
      assertTrue("String_Node_Str",query.getUpdateCount() == -1);
      assertTrue("String_Node_Str",query.getUpdateCount() == -1);
      assertTrue("String_Node_Str",query.getUpdateCount() == -1);
      assertTrue("String_Node_Str",query.getUpdateCount() == -1);
      Object outputParamValueFromName=query.getOutputParameterValue("String_Node_Str");
      assertNotNull("String_Node_Str",outputParamValueFromName);
      if (outputParamValueFromName instanceof Long) {
        assertTrue("String_Node_Str" + numberOfEmployes + "String_Node_Str"+ outputParamValueFromName,outputParamValueFromName.equals(new Long(numberOfEmployes)));
      }
 else {
        assertTrue("String_Node_Str" + numberOfEmployes + "String_Node_Str"+ outputParamValueFromName,outputParamValueFromName.equals(numberOfEmployes));
      }
      try {
        query.getOutputParameterValue(null);
        fail("String_Node_Str");
      }
 catch (      IllegalArgumentException e) {
      }
      try {
        query.getOutputParameterValue("String_Node_Str");
        fail("String_Node_Str");
      }
 catch (      IllegalArgumentException e) {
      }
      try {
        query.getOutputParameterValue("String_Node_Str");
        fail("String_Node_Str");
      }
 catch (      IllegalArgumentException e) {
      }
      Integer outputParamValueFromPosition=(Integer)query.getOutputParameterValue(3);
      assertNotNull("String_Node_Str",outputParamValueFromPosition);
      assertTrue("String_Node_Str" + numberOfEmployes + "String_Node_Str"+ outputParamValueFromPosition,outputParamValueFromPosition.equals(numberOfEmployes));
      try {
        query.getOutputParameterValue(8);
        fail("String_Node_Str");
      }
 catch (      IllegalArgumentException e) {
      }
      try {
        query.getOutputParameterValue(1);
        fail("String_Node_Str");
      }
 catch (      IllegalArgumentException e) {
      }
      Address a1=em.find(Address.class,address1.getId());
      assertTrue("String_Node_Str",a1.getPostalCode().equals(postalCodeCorrection));
      Address a2=em.find(Address.class,address2.getId());
      assertTrue("String_Node_Str",a2.getPostalCode().equals(postalCodeCorrection));
      Address a3=em.find(Address.class,address3.getId());
      assertTrue("String_Node_Str",a3.getPostalCode().equals(postalCodeCorrection));
    }
 catch (    RuntimeException e) {
      if (isTransactionActive(em)) {
        rollbackTransaction(em);
      }
      throw e;
    }
 finally {
      closeEntityManager(em);
    }
  }
}

Fixed version (ground truth):
/** 
 * Tests a StoredProcedureQuery that does an update though EM API  This is the same test as above except different retrieval path.
 */
public void testEMCreateStoredProcedureExecuteQuery2(){
  if (supportsStoredProcedures() && getPlatform().isMySQL()) {
    EntityManager em=createEntityManager();
    try {
      String postalCodeTypo="String_Node_Str";
      String postalCodeCorrection="String_Node_Str";
      beginTransaction(em);
      Address address1=new Address();
      address1.setCity("String_Node_Str");
      address1.setPostalCode(postalCodeTypo);
      address1.setProvince("String_Node_Str");
      address1.setStreet("String_Node_Str");
      address1.setCountry("String_Node_Str");
      em.persist(address1);
      Address address2=new Address();
      address2.setCity("String_Node_Str");
      address2.setPostalCode(postalCodeTypo);
      address2.setProvince("String_Node_Str");
      address2.setStreet("String_Node_Str");
      address2.setCountry("String_Node_Str");
      em.persist(address2);
      Address address3=new Address();
      address3.setCity("String_Node_Str");
      address3.setPostalCode(postalCodeCorrection);
      address3.setProvince("String_Node_Str");
      address3.setStreet("String_Node_Str");
      address3.setCountry("String_Node_Str");
      em.persist(address3);
      commitTransaction(em);
      em.clear();
      clearCache();
      StoredProcedureQuery query=em.createStoredProcedureQuery("String_Node_Str",Address.class,Employee.class);
      query.registerStoredProcedureParameter("String_Node_Str",String.class,ParameterMode.IN);
      query.registerStoredProcedureParameter("String_Node_Str",String.class,ParameterMode.IN);
      query.registerStoredProcedureParameter("String_Node_Str",Integer.class,ParameterMode.OUT);
      boolean result=query.setParameter("String_Node_Str",postalCodeCorrection).setParameter("String_Node_Str",postalCodeTypo).execute();
      assertTrue("String_Node_Str",result);
      assertTrue("String_Node_Str",query.hasMoreResults());
      assertTrue("String_Node_Str",query.hasMoreResults());
      assertTrue("String_Node_Str",query.hasMoreResults());
      assertTrue("String_Node_Str",query.hasMoreResults());
      assertTrue("String_Node_Str",query.hasMoreResults());
      assertTrue("String_Node_Str",query.hasMoreResults());
      assertTrue("String_Node_Str",query.hasMoreResults());
      List<Address> addressResults=query.getResultList();
      List<Employee> employeeResults=query.getResultList();
      int numberOfEmployes=employeeResults.size();
      assertFalse("String_Node_Str",query.hasMoreResults());
      assertFalse("String_Node_Str",query.hasMoreResults());
      assertFalse("String_Node_Str",query.hasMoreResults());
      assertFalse("String_Node_Str",query.hasMoreResults());
      assertNull("String_Node_Str",query.getResultList());
      int updateCount=query.getUpdateCount();
      assertTrue("String_Node_Str" + updateCount,updateCount == 2);
      assertTrue("String_Node_Str",query.getUpdateCount() == -1);
      assertTrue("String_Node_Str",query.getUpdateCount() == -1);
      assertTrue("String_Node_Str",query.getUpdateCount() == -1);
      assertTrue("String_Node_Str",query.getUpdateCount() == -1);
      assertTrue("String_Node_Str",query.getUpdateCount() == -1);
      Object outputParamValueFromName=query.getOutputParameterValue("String_Node_Str");
      assertNotNull("String_Node_Str",outputParamValueFromName);
      if (outputParamValueFromName instanceof Long) {
        assertTrue("String_Node_Str" + numberOfEmployes + "String_Node_Str"+ outputParamValueFromName,outputParamValueFromName.equals(new Long(numberOfEmployes)));
      }
 else       if (outputParamValueFromName instanceof Byte) {
        int value=((Byte)outputParamValueFromName).intValue();
        assertTrue("String_Node_Str" + numberOfEmployes + "String_Node_Str"+ value,value == numberOfEmployes);
      }
 else {
        assertTrue("String_Node_Str" + numberOfEmployes + "String_Node_Str"+ outputParamValueFromName,outputParamValueFromName.equals(numberOfEmployes));
      }
      try {
        query.getOutputParameterValue(null);
        fail("String_Node_Str");
      }
 catch (      IllegalArgumentException e) {
      }
      try {
        query.getOutputParameterValue("String_Node_Str");
        fail("String_Node_Str");
      }
 catch (      IllegalArgumentException e) {
      }
      try {
        query.getOutputParameterValue("String_Node_Str");
        fail("String_Node_Str");
      }
 catch (      IllegalArgumentException e) {
      }
      Integer outputParamValueFromPosition=(Integer)query.getOutputParameterValue(3);
      assertNotNull("String_Node_Str",outputParamValueFromPosition);
      assertTrue("String_Node_Str" + numberOfEmployes + "String_Node_Str"+ outputParamValueFromPosition,outputParamValueFromPosition.equals(numberOfEmployes));
      try {
        query.getOutputParameterValue(8);
        fail("String_Node_Str");
      }
 catch (      IllegalArgumentException e) {
      }
      try {
        query.getOutputParameterValue(1);
        fail("String_Node_Str");
      }
 catch (      IllegalArgumentException e) {
      }
      Address a1=em.find(Address.class,address1.getId());
      assertTrue("String_Node_Str",a1.getPostalCode().equals(postalCodeCorrection));
      Address a2=em.find(Address.class,address2.getId());
      assertTrue("String_Node_Str",a2.getPostalCode().equals(postalCodeCorrection));
      Address a3=em.find(Address.class,address3.getId());
      assertTrue("String_Node_Str",a3.getPostalCode().equals(postalCodeCorrection));
    }
 catch (    RuntimeException e) {
      if (isTransactionActive(em)) {
        rollbackTransaction(em);
      }
      throw e;
    }
 finally {
      closeEntityManager(em);
    }
  }
}