Buggy code:
public class Engine { private static Engine . SystemComparator comparator = new Engine . SystemComparator ( ) ; private Array < Entity > entities ; private ImmutableArray < Entity > immutableEntities ; private LongMap < Entity > entitiesById ; private Array < Engine . EntityOperation > entityOperations ; private Engine . EntityOperationPool entityOperationPool ; private Array < EntitySystem > systems ; private ImmutableArray < EntitySystem > immutableSystems ; private ObjectMap < Class < ? > , EntitySystem > systemsByClass ; private ObjectMap < Family , Array < Entity > > families ; private ObjectMap < Family , ImmutableArray < Entity > > immutableFamilies ; private SnapshotArray < EntityListener > listeners ; private ObjectMap < Family , SnapshotArray < EntityListener > > familyListeners ; private final Listener < Entity > componentAdded ; private final Listener < Entity > componentRemoved ; private boolean updating ; private boolean notifying ; private long nextEntityId = 1 ; private Engine . ComponentOperationPool componentOperationsPool ; private Array < Engine . ComponentOperation > componentOperations ; private Engine . ComponentOperationHandler componentOperationHandler ; public Engine ( ) { } private long obtainEntityId ( ) { } public void addEntity ( Entity entity ) { entity . uuid = obtainEntityId ( ) ; <START_BUG> if ( notifying ) { <END_BUG> Engine . EntityOperation operation = entityOperationPool . obtain ( ) ; operation . entity = entity ; operation . type = Engine . EntityOperation . Type . Add ; entityOperations . add ( operation ) ; } else { addEntityInternal ( entity ) ; } } public void removeEntity ( Entity entity ) { } public void removeAllEntities ( ) { } public Entity getEntity ( long id ) { } public ImmutableArray < Entity > getEntities ( ) { } public void addSystem ( EntitySystem system ) { } public void removeSystem ( EntitySystem system ) { } @ SuppressWarnings ( "unchecked" ) public < T extends EntitySystem > T getSystem ( Class < T > systemType ) { } public ImmutableArray < EntitySystem > getSystems ( ) { } public ImmutableArray < Entity > getEntitiesFor ( Family family ) { } public void addEntityListener ( EntityListener listener ) { } public void addEntityListener ( Family family , EntityListener listener ) { } public void removeEntityListener ( EntityListener listener ) { } public void update ( float deltaTime ) { } private void updateFamilyMembership ( Entity entity ) { } protected void removeEntityInternal ( Entity entity ) { } protected void addEntityInternal ( Entity entity ) { } private void notifyFamilyListenersAdd ( Family family , Entity entity ) { } private void notifyFamilyListenersRemove ( Family family , Entity entity ) { } private ImmutableArray < Entity > registerFamily ( Family family ) { } private void processPendingEntityOperations ( ) { } private void processComponentOperations ( ) { } private static class ComponentListener implements Listener < Entity > { private Engine engine ; public ComponentListener ( Engine engine ) { } @ Override public void receive ( Signal < Entity > signal , Entity object ) { } } static class ComponentOperationHandler { private Engine engine ; public ComponentOperationHandler ( Engine engine ) { } public void add ( Entity entity , Component component ) { } public void remove ( Entity entity , Class < ? extends Component > componentClass ) { } } private static class ComponentOperation implements Pool . Poolable { public enum Type { Add , Remove ; } public Engine . ComponentOperation . Type type ; public Entity entity ; public Component component ; public Class < ? extends Component > componentClass ; public void makeAdd ( Entity entity , Component component ) { } public void makeRemove ( Entity entity , Class < ? extends Component > componentClass ) { } @ Override public void reset ( ) { } } private static class ComponentOperationPool extends Pool < Engine . ComponentOperation > { @ Override protected Engine . ComponentOperation newObject ( ) { } } private static class SystemComparator implements Comparator < EntitySystem > { @ Override public int compare ( EntitySystem a , EntitySystem b ) { } } private static class EntityOperation implements Pool . Poolable { public enum Type { Add , Remove , RemoveAll ; } public Engine . EntityOperation . Type type ; public Entity entity ; @ Override public void reset ( ) { } } private static class EntityOperationPool extends Pool < Engine . EntityOperation > { @ Override protected Engine . EntityOperation newObject ( ) { } } }

Fix:
if ( ( updating ) || ( notifying ) ) {