{"record":{"id":"9fecb4c65cd4a557","repo":"apache/hadoop","slug":"default-replication-is-negative","errorCode":null,"errorMessage":"Default Replication is negative","messagePattern":"Default Replication is negative","errorType":"exception","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/protocol/CachePoolInfo.java","lineNumber":226,"sourceCode":"        append(ownerName).\n        append(groupName).\n        append(mode).\n        append(limit).\n        append(defaultReplication).\n        append(maxRelativeExpiryMs).\n        hashCode();\n  }\n\n  public static void validate(CachePoolInfo info) throws IOException {\n    if (info == null) {\n      throw new InvalidRequestException(\"CachePoolInfo is null\");\n    }\n    if ((info.getLimit() != null) && (info.getLimit() < 0)) {\n      throw new InvalidRequestException(\"Limit is negative.\");\n    }\n    if ((info.getDefaultReplication() != null)\n            && (info.getDefaultReplication() < 0)) {\n      throw new InvalidRequestException(\"Default Replication is negative\");\n    }\n\n    if (info.getMaxRelativeExpiryMs() != null) {\n      long maxRelativeExpiryMs = info.getMaxRelativeExpiryMs();\n      if (maxRelativeExpiryMs < 0l) {\n        throw new InvalidRequestException(\"Max relative expiry is negative.\");\n      }\n      if (maxRelativeExpiryMs > Expiration.MAX_RELATIVE_EXPIRY_MS) {\n        throw new InvalidRequestException(\"Max relative expiry is too big.\");\n      }\n    }\n    validateName(info.poolName);\n  }\n\n  public static void validateName(String poolName) throws IOException {\n    if (poolName == null || poolName.isEmpty()) {\n      // Empty pool names are not allowed because they would be highly\n      // confusing.  They would also break the ability to list all pools","sourceCodeStart":208,"sourceCodeEnd":244,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/protocol/CachePoolInfo.java#L208-L244","documentation":"CachePoolInfo.validate() rejects a cache pool whose default replication factor is set to a negative value. The default replication controls how many cached replicas the NameNode aims for for directives in this pool that do not override replication.","triggerScenarios":"addCachePool/modifyCachePool with CachePoolInfo.setDefaultReplication(negative), e.g. -1 from unset-variable arithmetic or from misreading '0 means default' semantics.","commonSituations":"Configuration-driven pool creation where the replication property is missing and parsed as a negative sentinel; code copied from block replication handling.","solutions":["Pass a non-negative short (0 means use the system default, >0 sets an explicit default replication).","Omit setDefaultReplication entirely to inherit the system default.","Guard external input: if (repl != null && repl >= 0) info.setDefaultReplication(repl);"],"exampleFix":"// before\ninfo.setDefaultReplication(Short.parseShort(cfg.get(\"pool.replication\", \"-1\")));\n\n// after\nString v = cfg.get(\"pool.replication\");\nif (v != null) {\n  short repl = Short.parseShort(v);\n  if (repl >= 0) info.setDefaultReplication(repl);\n}","handlingStrategy":"validation","validationCode":"if (repl != null && (repl < 0 || repl > Short.MAX_VALUE)) {\n  throw new IllegalArgumentException(\"default replication must be in [0, 32767], got \" + repl);\n}\ninfo.setDefaultReplication(repl);","typeGuard":null,"tryCatchPattern":"try { dfs.modifyCachePool(info); }\ncatch (InvalidRequestException e) { /* fix the source of the negative value, then retry */ }","preventionTips":["Parse replication from config with explicit range checks.","Remember 0 means 'use system default' — never pass -1 hoping it means unlimited.","Unit-test cache pool builders with boundary values (0, MAX_VALUE, negatives)."],"tags":["hdfs","caching","validation","replication"],"backgroundTag":"input-validation-failed","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}