@SuppressWarnings("unchecked")
    public <T extends AppState> T getState(Class<T> stateClass, boolean failOnMiss) {
        synchronized (states) {
            AppState[] array = getStates();
            for (AppState state : array) {
                if (stateClass.isAssignableFrom(state.getClass())) {
                    return (T) state;
                }
            }

            // This may be more trouble than it's worth, but I think
            // it's necessary for proper decoupling of states and provides
            // similar behavior to before where a state could be looked
            // up even if it wasn't initialized. -pspeed
            array = getInitializing();
            for (AppState state : array) {
                if (stateClass.isAssignableFrom(state.getClass())) {
                    return (T) state;
                }
            }
        }

        if (failOnMiss) {
            throw new IllegalArgumentException("State not found for:" + stateClass);
        }
        return null;
    }
Returns the first state that is an instance of subclass of the specified class.

@param <T> the desired type of AppState
@param stateClass the desired type of AppState
@param failOnMiss true to throw an exception, false to return null
@return First attached state that is an instance of stateClass. If failOnMiss is true
    then an IllegalArgumentException is thrown if the state is not attached.
jme3-core/src/main/java/com/jme3/app/state/AppStateManager.java