{"record":{"id":"949756fef1209b17","repo":"apache/hadoop","slug":"cannot-set-a-negative-expiration-expiry-getmilli","errorCode":null,"errorMessage":"Cannot set a negative expiration: {expiry.getMillis()}","messagePattern":"Cannot set a negative expiration: (.+?)","errorType":"exception","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/CacheManager.java","lineNumber":423,"sourceCode":"   * \n   * @param info to validate.\n   * @param maxRelativeExpiryTime of the info's pool.\n   * @return the expiration time, or the pool's max absolute expiration if the\n   *         info's expiration was not set.\n   * @throws InvalidRequestException if the info's Expiration is invalid.\n   */\n  private static long validateExpiryTime(CacheDirectiveInfo info,\n      long maxRelativeExpiryTime) throws InvalidRequestException {\n    LOG.trace(\"Validating directive {} pool maxRelativeExpiryTime {}\", info,\n        maxRelativeExpiryTime);\n    final long now = new Date().getTime();\n    final long maxAbsoluteExpiryTime = now + maxRelativeExpiryTime;\n    if (info == null || info.getExpiration() == null) {\n      return maxAbsoluteExpiryTime;\n    }\n    Expiration expiry = info.getExpiration();\n    if (expiry.getMillis() < 0l) {\n      throw new InvalidRequestException(\"Cannot set a negative expiration: \"\n          + expiry.getMillis());\n    }\n    long relExpiryTime, absExpiryTime;\n    if (expiry.isRelative()) {\n      relExpiryTime = expiry.getMillis();\n      absExpiryTime = now + relExpiryTime;\n    } else {\n      absExpiryTime = expiry.getMillis();\n      relExpiryTime = absExpiryTime - now;\n    }\n    // Need to cap the expiry so we don't overflow a long when doing math\n    if (relExpiryTime > Expiration.MAX_RELATIVE_EXPIRY_MS) {\n      throw new InvalidRequestException(\"Expiration \"\n          + expiry.toString() + \" is too far in the future!\");\n    }\n    // Fail if the requested expiry is greater than the max\n    if (relExpiryTime > maxRelativeExpiryTime) {\n      throw new InvalidRequestException(\"Expiration \" + expiry.toString()","sourceCodeStart":405,"sourceCodeEnd":441,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/CacheManager.java#L405-L441","documentation":"Error \"Cannot set a negative expiration: {expiry.getMillis()}\" thrown in apache/hadoop.","triggerScenarios":"addCacheDirective/modify with a negative expiration time.","commonSituations":"See trigger scenarios.","solutions":["Use a positive TTL/expiration for the cache directive (e.g. -ttl 3600000 or 'never')."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}