code: protected void checkValidForWrite() throws IllegalStateException {
          checkLocked();
  
          if (state == State.INVALID) {
              throw new IllegalStateException("Not valid for write: session " + this);
          }
          if (state == State.INVALIDATING) {
              return;  // in the process of being invalidated, listeners may try to remove attributes
          }
          if (!isResident()) {
              throw new IllegalStateException("Not valid for write: session " + this);
          }
      }
docs: Check that the session can be modified.
  
  @throws IllegalStateException if the session is invalid