private static boolean isValid(Cipher cipher) {
    try {
      AlgorithmParameterSpec params = new IvParameterSpec(TEST_NONCE);
      cipher.init(Cipher.DECRYPT_MODE, new SecretKeySpec(TEST_KEY, KEY_NAME), params);
      byte[] output = cipher.doFinal(TEST_CIPHERTEXT_OF_EMPTY);
      if (output.length != 0) {
        return false;
      }
      // Decrypt a 2nd time. This fails on OpenJDK11 because of a bug.
      cipher.init(Cipher.DECRYPT_MODE, new SecretKeySpec(TEST_KEY, KEY_NAME), params);
      byte[] output2 = cipher.doFinal(TEST_CIPHERTEXT_OF_EMPTY);
      if (output2.length != 0) {
        return false;
      }
      return true;
    } catch (GeneralSecurityException ex) {
      return false;
    }
  }
ChaCha20Poly1305Jce implements an AEAD for ChaCha20Poly1305, as described in <a
href="https://tools.ietf.org/html/rfc8439#section-2.8">RFC 8439, section 2.8</a>.

<p>It uses the JCE, and requires that algorithm "ChaCha20-Poly1305" is present.
java_src/src/main/java/com/google/crypto/tink/aead/internal/ChaCha20Poly1305Jce.java