bson/src/main/org/bson/AbstractBsonWriter.java
protected void checkPreconditions(final String methodName, final State... validStates) {
        if (isClosed()) {
            throw new IllegalStateException("BsonWriter is closed");
        }

        if (!checkState(validStates)) {
            throwInvalidState(methodName, validStates);
        }
    }
protected void checkPreconditions(final String methodName, final State... validStates) {
        if (isClosed()) {
            throw new IllegalStateException("BsonWriter is closed");
        }

        if (!checkState(validStates)) {
            throwInvalidState(methodName, validStates);
        }
    }
Checks the writer is in the correct state. If the writer's current state is in the list of given states, this method will complete
without exception.  Throws an {@link java.lang.IllegalStateException} if the writer is closed.  Throws BsonInvalidOperationException
if the method is trying to do something that is not permitted in the current state.

@param methodName  the name of the method being performed that checks are being performed for
@param validStates the list of valid states for this operation
@see #throwInvalidState(String, org.bson.AbstractBsonWriter.State...)