Program: 63371
Project: 63371
Buggy source:
@SuppressWarnings("String_Node_Str") @Test @Bugzilla(bugid=317760) public void testRelationshipToRemoved(){
  JPAEnvironment env=getEnvironment();
  EntityManager em=env.getEntityManager();
  try {
    Department dep=new Department(101,"String_Node_Str");
    Employee emp1=new Employee(102,"String_Node_Str","String_Node_Str",dep);
    Cubicle cub1=new Cubicle(new Integer(103),new Integer(103),"String_Node_Str",emp1);
    emp1.setCubicle(cub1);
    env.beginTransaction(em);
    em.persist(dep);
    em.persist(emp1);
    em.persist(cub1);
    env.commitTransactionAndClear(em);
    env.beginTransaction(em);
    emp1=em.find(Employee.class,new Integer(emp1.getId()));
    cub1=em.find(Cubicle.class,cub1.getId());
    cub1.setEmployee(null);
    em.remove(cub1);
    boolean flushOrCommmitFailed=false;
    try {
      em.flush();
    }
 catch (    IllegalStateException e) {
      flushOrCommmitFailed=true;
      verify(env.isTransactionMarkedForRollback(em),"String_Node_Str");
      env.rollbackTransactionAndClear(em);
    }
    try {
      if (env.isTransactionActive(em)) {
        env.commitTransactionAndClear(em);
      }
    }
 catch (    RuntimeException e) {
      if (!checkForIllegalStateException(e)) {
        throw e;
      }
      flushOrCommmitFailed=true;
    }
    verify(!env.isTransactionActive(em),"String_Node_Str");
    verify(flushOrCommmitFailed,"String_Node_Str");
    em.clear();
    dep=new Department(104,"String_Node_Str");
    emp1=new Employee(105,"String_Node_Str","String_Node_Str",dep);
    Project proj=new Project("String_Node_Str");
    Set<Project> emp1Projects=new HashSet<Project>();
    emp1Projects.add(proj);
    emp1.setProjects(emp1Projects);
    Set<Employee> projEmployees=new HashSet<Employee>();
    projEmployees.add(emp1);
    proj.setEmployees(projEmployees);
    env.beginTransaction(em);
    em.persist(proj);
    em.persist(dep);
    em.persist(emp1);
    env.commitTransactionAndClear(em);
    env.beginTransaction(em);
    emp1=em.find(Employee.class,new Integer(emp1.getId()));
    proj=em.find(Project.class,proj.getId());
    emp1.getProjects().size();
    em.remove(proj);
    flushOrCommmitFailed=false;
    try {
      em.flush();
    }
 catch (    IllegalStateException e) {
      flushOrCommmitFailed=true;
      verify(env.isTransactionMarkedForRollback(em),"String_Node_Str");
      env.rollbackTransactionAndClear(em);
    }
    try {
      if (env.isTransactionActive(em)) {
        env.commitTransactionAndClear(em);
      }
    }
 catch (    RuntimeException e) {
      if (!checkForIllegalStateException(e)) {
        throw e;
      }
      flushOrCommmitFailed=true;
    }
    verify(!env.isTransactionActive(em),"String_Node_Str");
    verify(flushOrCommmitFailed,"String_Node_Str");
    em.clear();
    dep=new Department(107,"String_Node_Str");
    emp1=new Employee(108,"String_Node_Str","String_Node_Str",dep);
    Employee emp2=new Employee(109,"String_Node_Str","String_Node_Str",dep);
    proj=new Project("String_Node_Str");
    emp1Projects=new HashSet<Project>();
    emp1Projects.add(proj);
    emp1.setProjects(emp1Projects);
    Set<Project> emp2Projects=new HashSet<Project>();
    emp2Projects.add(proj);
    emp2.setProjects(emp2Projects);
    projEmployees=new HashSet<Employee>();
    projEmployees.add(emp1);
    projEmployees.add(emp2);
    proj.setEmployees(projEmployees);
    env.beginTransaction(em);
    em.persist(proj);
    em.persist(dep);
    em.persist(emp1);
    em.persist(emp2);
    env.commitTransactionAndClear(em);
    env.beginTransaction(em);
    emp1=em.find(Employee.class,new Integer(emp1.getId()));
    emp2=em.find(Employee.class,new Integer(emp2.getId()));
    proj=em.find(Project.class,proj.getId());
    emp1.getProjects().size();
    proj.getEmployees().size();
    em.remove(emp2);
    flushOrCommmitFailed=false;
    try {
      em.flush();
    }
 catch (    IllegalStateException e) {
      flushOrCommmitFailed=true;
      verify(env.isTransactionMarkedForRollback(em),"String_Node_Str");
      env.rollbackTransactionAndClear(em);
    }
    try {
      if (env.isTransactionActive(em)) {
        env.commitTransactionAndClear(em);
      }
    }
 catch (    RuntimeException e) {
      if (!checkForIllegalStateException(e)) {
        throw e;
      }
      flushOrCommmitFailed=true;
    }
    verify(!env.isTransactionActive(em),"String_Node_Str");
    verify(flushOrCommmitFailed,"String_Node_Str");
    em.clear();
    dep=new Department(111,"String_Node_Str");
    emp1=new Employee(112,"String_Node_Str","String_Node_Str",dep);
    cub1=new Cubicle(new Integer(113),new Integer(112),"String_Node_Str",emp1);
    env.beginTransaction(em);
    em.persist(dep);
    em.persist(emp1);
    em.persist(cub1);
    env.commitTransactionAndClear(em);
    env.beginTransaction(em);
    emp1=em.find(Employee.class,new Integer(emp1.getId()));
    cub1=em.find(Cubicle.class,cub1.getId());
    em.remove(cub1);
    em.flush();
    emp1.setCubicle(cub1);
    flushOrCommmitFailed=false;
    try {
      em.flush();
    }
 catch (    IllegalStateException e) {
      flushOrCommmitFailed=true;
      verify(env.isTransactionMarkedForRollback(em),"String_Node_Str");
      env.rollbackTransactionAndClear(em);
    }
    try {
      if (env.isTransactionActive(em)) {
        env.commitTransactionAndClear(em);
      }
    }
 catch (    RuntimeException e) {
      if (!checkForIllegalStateException(e)) {
        throw e;
      }
      flushOrCommmitFailed=true;
    }
    verify(!env.isTransactionActive(em),"String_Node_Str");
    verify(flushOrCommmitFailed,"String_Node_Str");
    em.clear();
    dep=new Department(114,"String_Node_Str");
    emp1=new Employee(115,"String_Node_Str","String_Node_Str",dep);
    proj=new Project("String_Node_Str");
    env.beginTransaction(em);
    em.persist(dep);
    em.persist(emp1);
    em.persist(proj);
    env.commitTransactionAndClear(em);
    env.beginTransaction(em);
    emp1=em.find(Employee.class,new Integer(emp1.getId()));
    proj=em.find(Project.class,proj.getId());
    em.remove(proj);
    em.flush();
    emp1Projects=new HashSet<Project>();
    emp1Projects.add(proj);
    emp1.setProjects(emp1Projects);
    projEmployees=new HashSet<Employee>();
    projEmployees.add(emp1);
    proj.setEmployees(projEmployees);
    flushOrCommmitFailed=false;
    try {
      em.flush();
    }
 catch (    IllegalStateException e) {
      flushOrCommmitFailed=true;
      verify(env.isTransactionMarkedForRollback(em),"String_Node_Str");
      env.rollbackTransactionAndClear(em);
    }
    try {
      if (env.isTransactionActive(em)) {
        env.commitTransactionAndClear(em);
      }
    }
 catch (    RuntimeException e) {
      if (!checkForIllegalStateException(e)) {
        throw e;
      }
      flushOrCommmitFailed=true;
    }
    verify(!env.isTransactionActive(em),"String_Node_Str");
    verify(flushOrCommmitFailed,"String_Node_Str");
    em.clear();
    dep=new Department(117,"String_Node_Str");
    emp1=new Employee(118,"String_Node_Str","String_Node_Str",dep);
    emp2=new Employee(119,"String_Node_Str","String_Node_Str",dep);
    proj=new Project("String_Node_Str");
    emp1Projects=new HashSet<Project>();
    emp1Projects.add(proj);
    emp1.setProjects(emp1Projects);
    projEmployees=new HashSet<Employee>();
    projEmployees.add(emp1);
    proj.setEmployees(projEmployees);
    env.beginTransaction(em);
    em.persist(proj);
    em.persist(dep);
    em.persist(emp1);
    em.persist(emp2);
    env.commitTransactionAndClear(em);
    env.beginTransaction(em);
    emp1=em.find(Employee.class,new Integer(emp1.getId()));
    emp2=em.find(Employee.class,new Integer(emp2.getId()));
    proj=em.find(Project.class,proj.getId());
    emp1.getProjects().size();
    projEmployees=proj.getEmployees();
    projEmployees.size();
    em.remove(emp2);
    em.flush();
    emp2Projects=new HashSet<Project>();
    emp2Projects.add(proj);
    emp2.setProjects(emp2Projects);
    projEmployees.add(emp2);
    flushOrCommmitFailed=false;
    try {
      em.flush();
    }
 catch (    IllegalStateException e) {
      flushOrCommmitFailed=true;
      verify(env.isTransactionMarkedForRollback(em),"String_Node_Str");
      env.rollbackTransactionAndClear(em);
    }
    try {
      if (env.isTransactionActive(em)) {
        env.commitTransactionAndClear(em);
      }
    }
 catch (    RuntimeException e) {
      if (!checkForIllegalStateException(e)) {
        throw e;
      }
      flushOrCommmitFailed=true;
    }
    verify(!env.isTransactionActive(em),"String_Node_Str");
    verify(flushOrCommmitFailed,"String_Node_Str");
    em.clear();
  }
  finally {
    closeEntityManager(em);
  }
}

Fixed version (ground truth):
@SuppressWarnings("String_Node_Str") @Test @Bugzilla(bugid=311760) public void testRelationshipToRemoved(){
  JPAEnvironment env=getEnvironment();
  EntityManager em=env.getEntityManager();
  try {
    Department dep=new Department(101,"String_Node_Str");
    Employee emp1=new Employee(102,"String_Node_Str","String_Node_Str",dep);
    Cubicle cub1=new Cubicle(new Integer(103),new Integer(103),"String_Node_Str",emp1);
    emp1.setCubicle(cub1);
    env.beginTransaction(em);
    em.persist(dep);
    em.persist(emp1);
    em.persist(cub1);
    env.commitTransactionAndClear(em);
    env.beginTransaction(em);
    emp1=em.find(Employee.class,new Integer(emp1.getId()));
    cub1=em.find(Cubicle.class,cub1.getId());
    cub1.setEmployee(null);
    em.remove(cub1);
    boolean flushOrCommmitFailed=false;
    try {
      em.flush();
    }
 catch (    IllegalStateException e) {
      flushOrCommmitFailed=true;
      verify(env.isTransactionMarkedForRollback(em),"String_Node_Str");
      env.rollbackTransactionAndClear(em);
    }
    try {
      if (env.isTransactionActive(em)) {
        env.commitTransactionAndClear(em);
      }
    }
 catch (    RuntimeException e) {
      if (!checkForIllegalStateException(e)) {
        throw e;
      }
      flushOrCommmitFailed=true;
    }
    verify(!env.isTransactionActive(em),"String_Node_Str");
    verify(flushOrCommmitFailed,"String_Node_Str");
    em.clear();
    dep=new Department(104,"String_Node_Str");
    emp1=new Employee(105,"String_Node_Str","String_Node_Str",dep);
    Project proj=new Project("String_Node_Str");
    Set<Project> emp1Projects=new HashSet<Project>();
    emp1Projects.add(proj);
    emp1.setProjects(emp1Projects);
    Set<Employee> projEmployees=new HashSet<Employee>();
    projEmployees.add(emp1);
    proj.setEmployees(projEmployees);
    env.beginTransaction(em);
    em.persist(proj);
    em.persist(dep);
    em.persist(emp1);
    env.commitTransactionAndClear(em);
    env.beginTransaction(em);
    emp1=em.find(Employee.class,new Integer(emp1.getId()));
    proj=em.find(Project.class,proj.getId());
    emp1.getProjects().size();
    em.remove(proj);
    flushOrCommmitFailed=false;
    try {
      em.flush();
    }
 catch (    IllegalStateException e) {
      flushOrCommmitFailed=true;
      verify(env.isTransactionMarkedForRollback(em),"String_Node_Str");
      env.rollbackTransactionAndClear(em);
    }
    try {
      if (env.isTransactionActive(em)) {
        env.commitTransactionAndClear(em);
      }
    }
 catch (    RuntimeException e) {
      if (!checkForIllegalStateException(e)) {
        throw e;
      }
      flushOrCommmitFailed=true;
    }
    verify(!env.isTransactionActive(em),"String_Node_Str");
    verify(flushOrCommmitFailed,"String_Node_Str");
    em.clear();
    dep=new Department(107,"String_Node_Str");
    emp1=new Employee(108,"String_Node_Str","String_Node_Str",dep);
    Employee emp2=new Employee(109,"String_Node_Str","String_Node_Str",dep);
    proj=new Project("String_Node_Str");
    emp1Projects=new HashSet<Project>();
    emp1Projects.add(proj);
    emp1.setProjects(emp1Projects);
    Set<Project> emp2Projects=new HashSet<Project>();
    emp2Projects.add(proj);
    emp2.setProjects(emp2Projects);
    projEmployees=new HashSet<Employee>();
    projEmployees.add(emp1);
    projEmployees.add(emp2);
    proj.setEmployees(projEmployees);
    env.beginTransaction(em);
    em.persist(proj);
    em.persist(dep);
    em.persist(emp1);
    em.persist(emp2);
    env.commitTransactionAndClear(em);
    env.beginTransaction(em);
    emp1=em.find(Employee.class,new Integer(emp1.getId()));
    emp2=em.find(Employee.class,new Integer(emp2.getId()));
    proj=em.find(Project.class,proj.getId());
    emp1.getProjects().size();
    proj.getEmployees().size();
    em.remove(emp2);
    flushOrCommmitFailed=false;
    try {
      em.flush();
    }
 catch (    IllegalStateException e) {
      flushOrCommmitFailed=true;
      verify(env.isTransactionMarkedForRollback(em),"String_Node_Str");
      env.rollbackTransactionAndClear(em);
    }
    try {
      if (env.isTransactionActive(em)) {
        env.commitTransactionAndClear(em);
      }
    }
 catch (    RuntimeException e) {
      if (!checkForIllegalStateException(e)) {
        throw e;
      }
      flushOrCommmitFailed=true;
    }
    verify(!env.isTransactionActive(em),"String_Node_Str");
    verify(flushOrCommmitFailed,"String_Node_Str");
    em.clear();
    dep=new Department(111,"String_Node_Str");
    emp1=new Employee(112,"String_Node_Str","String_Node_Str",dep);
    cub1=new Cubicle(new Integer(113),new Integer(112),"String_Node_Str",emp1);
    env.beginTransaction(em);
    em.persist(dep);
    em.persist(emp1);
    em.persist(cub1);
    env.commitTransactionAndClear(em);
    env.beginTransaction(em);
    emp1=em.find(Employee.class,new Integer(emp1.getId()));
    cub1=em.find(Cubicle.class,cub1.getId());
    em.remove(cub1);
    em.flush();
    emp1.setCubicle(cub1);
    flushOrCommmitFailed=false;
    try {
      em.flush();
    }
 catch (    IllegalStateException e) {
      flushOrCommmitFailed=true;
      verify(env.isTransactionMarkedForRollback(em),"String_Node_Str");
      env.rollbackTransactionAndClear(em);
    }
    try {
      if (env.isTransactionActive(em)) {
        env.commitTransactionAndClear(em);
      }
    }
 catch (    RuntimeException e) {
      if (!checkForIllegalStateException(e)) {
        throw e;
      }
      flushOrCommmitFailed=true;
    }
    verify(!env.isTransactionActive(em),"String_Node_Str");
    verify(flushOrCommmitFailed,"String_Node_Str");
    em.clear();
    dep=new Department(114,"String_Node_Str");
    emp1=new Employee(115,"String_Node_Str","String_Node_Str",dep);
    proj=new Project("String_Node_Str");
    env.beginTransaction(em);
    em.persist(dep);
    em.persist(emp1);
    em.persist(proj);
    env.commitTransactionAndClear(em);
    env.beginTransaction(em);
    emp1=em.find(Employee.class,new Integer(emp1.getId()));
    proj=em.find(Project.class,proj.getId());
    em.remove(proj);
    em.flush();
    emp1Projects=new HashSet<Project>();
    emp1Projects.add(proj);
    emp1.setProjects(emp1Projects);
    projEmployees=new HashSet<Employee>();
    projEmployees.add(emp1);
    proj.setEmployees(projEmployees);
    flushOrCommmitFailed=false;
    try {
      em.flush();
    }
 catch (    IllegalStateException e) {
      flushOrCommmitFailed=true;
      verify(env.isTransactionMarkedForRollback(em),"String_Node_Str");
      env.rollbackTransactionAndClear(em);
    }
    try {
      if (env.isTransactionActive(em)) {
        env.commitTransactionAndClear(em);
      }
    }
 catch (    RuntimeException e) {
      if (!checkForIllegalStateException(e)) {
        throw e;
      }
      flushOrCommmitFailed=true;
    }
    verify(!env.isTransactionActive(em),"String_Node_Str");
    verify(flushOrCommmitFailed,"String_Node_Str");
    em.clear();
    dep=new Department(117,"String_Node_Str");
    emp1=new Employee(118,"String_Node_Str","String_Node_Str",dep);
    emp2=new Employee(119,"String_Node_Str","String_Node_Str",dep);
    proj=new Project("String_Node_Str");
    emp1Projects=new HashSet<Project>();
    emp1Projects.add(proj);
    emp1.setProjects(emp1Projects);
    projEmployees=new HashSet<Employee>();
    projEmployees.add(emp1);
    proj.setEmployees(projEmployees);
    env.beginTransaction(em);
    em.persist(proj);
    em.persist(dep);
    em.persist(emp1);
    em.persist(emp2);
    env.commitTransactionAndClear(em);
    env.beginTransaction(em);
    emp1=em.find(Employee.class,new Integer(emp1.getId()));
    emp2=em.find(Employee.class,new Integer(emp2.getId()));
    proj=em.find(Project.class,proj.getId());
    emp1.getProjects().size();
    projEmployees=proj.getEmployees();
    projEmployees.size();
    em.remove(emp2);
    em.flush();
    emp2Projects=new HashSet<Project>();
    emp2Projects.add(proj);
    emp2.setProjects(emp2Projects);
    projEmployees.add(emp2);
    flushOrCommmitFailed=false;
    try {
      em.flush();
    }
 catch (    IllegalStateException e) {
      flushOrCommmitFailed=true;
      verify(env.isTransactionMarkedForRollback(em),"String_Node_Str");
      env.rollbackTransactionAndClear(em);
    }
    try {
      if (env.isTransactionActive(em)) {
        env.commitTransactionAndClear(em);
      }
    }
 catch (    RuntimeException e) {
      if (!checkForIllegalStateException(e)) {
        throw e;
      }
      flushOrCommmitFailed=true;
    }
    verify(!env.isTransactionActive(em),"String_Node_Str");
    verify(flushOrCommmitFailed,"String_Node_Str");
    em.clear();
  }
  finally {
    closeEntityManager(em);
  }
}