{"record":{"id":"da9c9a0d1883b698","repo":"apache/hadoop","slug":"perms-option-is-set-multiple-times","errorCode":null,"errorMessage":"Perms option is set multiple times","messagePattern":"Perms option is set multiple times","errorType":"validation","errorClass":"HadoopIllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/AbstractFileSystem.java","lineNumber":578,"sourceCode":"          throw new HadoopIllegalArgumentException(\n              \"ReplicationFactor option is set multiple times\");\n        }\n        replication = ((CreateOpts.ReplicationFactor) iOpt).getValue();\n      } else if (CreateOpts.BytesPerChecksum.class.isInstance(iOpt)) {\n        if (bytesPerChecksum != -1) {\n          throw new HadoopIllegalArgumentException(\n              \"BytesPerChecksum option is set multiple times\");\n        }\n        bytesPerChecksum = ((CreateOpts.BytesPerChecksum) iOpt).getValue();\n      } else if (CreateOpts.ChecksumParam.class.isInstance(iOpt)) {\n        if (checksumOpt != null) {\n          throw new  HadoopIllegalArgumentException(\n              \"CreateChecksumType option is set multiple times\");\n        }\n        checksumOpt = ((CreateOpts.ChecksumParam) iOpt).getValue();\n      } else if (CreateOpts.Perms.class.isInstance(iOpt)) {\n        if (permission != null) {\n          throw new HadoopIllegalArgumentException(\n              \"Perms option is set multiple times\");\n        }\n        permission = ((CreateOpts.Perms) iOpt).getValue();\n      } else if (CreateOpts.Progress.class.isInstance(iOpt)) {\n        if (progress != null) {\n          throw new HadoopIllegalArgumentException(\n              \"Progress option is set multiple times\");\n        }\n        progress = ((CreateOpts.Progress) iOpt).getValue();\n      } else if (CreateOpts.CreateParent.class.isInstance(iOpt)) {\n        if (createParent != null) {\n          throw new HadoopIllegalArgumentException(\n              \"CreateParent option is set multiple times\");\n        }\n        createParent = ((CreateOpts.CreateParent) iOpt).getValue();\n      } else {\n        throw new HadoopIllegalArgumentException(\"Unkown CreateOpts of type \" +\n            iOpt.getClass().getName());","sourceCodeStart":560,"sourceCodeEnd":596,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/AbstractFileSystem.java#L560-L596","documentation":"AbstractFileSystem.create requires exactly one CreateOpts.Perms entry; a second one throws HadoopIllegalArgumentException. FileContext.create never triggers this because it rebuilds the option array with CreateOpts.setOpt(CreateOpts.perms(...)) (FileContext.java:692-698), so this fires only for direct AbstractFileSystem.create callers who duplicate the perms option.","triggerScenarios":"Direct afs.create(path, flag, opts) with two CreateOpts.perms(...) entries in opts — e.g. custom framework code that appends a permission default to an array that already contains one.","commonSituations":"Custom FileContext-like wrappers that add their own default permission instead of using CreateOpts.setOpt; security layers injecting a hardened umask/permission over user opts by append.","solutions":["Pass CreateOpts.perms exactly once","Replace instead of append: CreateOpts.setOpt(CreateOpts.perms(p), opts)","Prefer FileContext.create, which applies umask and injects/replaces the perms option safely"],"exampleFix":"// before\nafs.create(f, flag, CreateOpts.perms(FsPermission.getFileDefault()),\n    CreateOpts.perms(perm));\n\n// after\nafs.create(f, flag, CreateOpts.perms(perm));","handlingStrategy":"validation","validationCode":"if (CreateOpts.getOpt(CreateOpts.Perms.class, opts) == null) {\n  opts = CreateOpts.setOpt(CreateOpts.perms(FsPermission.getFileDefault()), opts);\n}\nafs.create(f, flag, opts);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Prefer FileContext.create — it injects and umask-applies the permission via setOpt","In direct AbstractFileSystem wrappers, add perms with setOpt (replace), never append","Test wrappers against calls that already carry a Perms option"],"tags":["hadoop","file-create","options","permissions","varargs"],"backgroundTag":"duplicate-create-option","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}