[Demonstration 1]

[Buggy Method]
public void close() {
    if (closeEntityManager && entityManager != null && !entityManager.isOpen()) {
        try {
            entityManager.close();
        } catch (IllegalStateException ise) {
            throw new FlowableException("Error while closing EntityManager, may have already been closed or it is container-managed", ise);
        }
    }
}

[Buggy Hunk]
if (closeEntityManager && entityManager != null && !entityManager.isOpen()) {

[Patch]
if (closeEntityManager && entityManager != null && entityManager.isOpen()) {