code: private void checkCipherState() {
          if (!(this instanceof NullCipher)) {
              if (!initialized) {
                  throw new IllegalStateException("Cipher not initialized");
              }
              if ((opmode != Cipher.ENCRYPT_MODE) &&
                  (opmode != Cipher.DECRYPT_MODE)) {
                  throw new IllegalStateException("Cipher not initialized " +
                                                  "for encryption/decryption");
              }
          }
      }
docs: Ensures that Cipher is in a valid state for update() and doFinal()
  calls - should be initialized and in ENCRYPT_MODE or DECRYPT_MODE.
  @throws IllegalStateException if Cipher object is not in valid state.