{"record":{"id":"1ab50dfbbcac0b78","repo":"apache/hadoop","slug":"createnonrecursive-unsupported-for-this-filesystem","errorCode":null,"errorMessage":"createNonRecursive unsupported for this filesystem ${this.getClass()}","messagePattern":"createNonRecursive unsupported for this filesystem (.+?)","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileSystem.java","lineNumber":1483,"sourceCode":"   /**\n    * Opens an FSDataOutputStream at the indicated Path with write-progress\n    * reporting. Same as create(), except fails if parent directory doesn't\n    * already exist.\n    * @param f the file name to open\n    * @param permission file permission\n    * @param flags {@link CreateFlag}s to use for this stream.\n    * @param bufferSize the size of the buffer to be used.\n    * @param replication required block replication for the file.\n    * @param blockSize block size\n    * @param progress the progress reporter\n    * @throws IOException IO failure\n    * @see #setPermission(Path, FsPermission)\n    * @return output stream.\n    */\n    public FSDataOutputStream createNonRecursive(Path f, FsPermission permission,\n        EnumSet<CreateFlag> flags, int bufferSize, short replication, long blockSize,\n        Progressable progress) throws IOException {\n      throw new IOException(\"createNonRecursive unsupported for this filesystem \"\n          + this.getClass());\n    }\n\n  /**\n   * Creates the given Path as a brand-new zero-length file.  If\n   * create fails, or if it already existed, return false.\n   * <i>Important: the default implementation is not atomic</i>\n   * @param f path to use for create\n   * @throws IOException IO failure\n   * @return if create new file success true,not false.\n   */\n  public boolean createNewFile(Path f) throws IOException {\n    if (exists(f)) {\n      return false;\n    } else {\n      create(f, false, getConf().getInt(IO_FILE_BUFFER_SIZE_KEY,\n          IO_FILE_BUFFER_SIZE_DEFAULT)).close();\n      return true;","sourceCodeStart":1465,"sourceCodeEnd":1501,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileSystem.java#L1465-L1501","documentation":"createNonRecursive(f, ...) creates a file only when the parent already exists, but the base FileSystem has no generic way to enforce that, so the default throws IOException('createNonRecursive unsupported for this filesystem <class>'). Only FileSystems that explicitly override it (e.g. the local filesystem family) support the call.","triggerScenarios":"Calling fs.createNonRecursive(...) on an implementation that never overrode it - various third-party connectors and wrapper FileSystems.","commonSituations":"Shared job code written against local/HDFS behavior then run against object stores; MapReduce's non-recursive commit paths encountering an unexpected FileSystem class.","solutions":["Replace with fs.create(f, ...) after ensuring the parent yourself: fs.exists(parent) || fs.mkdirs(parent)","Branch on the filesystem type before choosing the non-recursive API","If you own the FileSystem, implement createNonRecursive"],"exampleFix":"// before\ntry (FSDataOutputStream out = fs.createNonRecursive(f, perm, false, buf, rep, block, null)) { }\n\n// after\nPath parent = f.getParent();\nif (!fs.exists(parent)) throw new FileNotFoundException(parent.toString());\ntry (FSDataOutputStream out = fs.create(f, true, buf, rep, block, null)) { }","handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  out = fs.createNonRecursive(f, perm, false, buf, rep, blockSize, null);\n} catch (IOException e) {\n  if (e.getMessage() != null && e.getMessage().contains(\"createNonRecursive unsupported\")) {\n    if (!fs.exists(f.getParent())) fs.mkdirs(f.getParent());\n    out = fs.create(f, true, buf, rep, blockSize, null);\n  } else {\n    throw e;\n  }\n}","preventionTips":["Treat non-standard FileSystem APIs as optional capabilities","Prefer create() plus your own parent validation for portability","Test job code against the local FileSystem to catch store assumptions"],"tags":["hadoop","filesystem","create","unsupported-operation"],"backgroundTag":"unsupported-filesystem-operation","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}