{"record":{"id":"b9cd63331bd4bdb6","repo":"apache/hadoop","slug":"failed-to-initialize-lost-found","errorCode":null,"errorMessage":"failed to initialize lost+found","messagePattern":"failed to initialize lost\\+found","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NamenodeFsck.java","lineNumber":1001,"sourceCode":"    try {\n      HdfsFileStatus hfs = namenode.getRpcServer().getFileInfo(path);\n      return (hfs != null);\n    } catch (FileNotFoundException e) {\n      return false;\n    }\n  }\n\n  private void copyBlocksToLostFound(String parent, HdfsFileStatus file,\n        LocatedBlocks blocks) throws IOException {\n    final DFSClient dfs = new DFSClient(DFSUtilClient.getNNAddress(conf), conf);\n    final String fullName = file.getFullName(parent);\n    OutputStream fos = null;\n    try {\n      if (!lfInited) {\n        lostFoundInit(dfs);\n      }\n      if (!lfInitedOk) {\n        throw new IOException(\"failed to initialize lost+found\");\n      }\n      String target = lostFound + fullName;\n      if (hdfsPathExists(target)) {\n        LOG.warn(\"Fsck: can't copy the remains of \" + fullName + \" to \" +\n          \"lost+found, because \" + target + \" already exists.\");\n        return;\n      }\n      if (!namenode.getRpcServer().mkdirs(\n          target, file.getPermission(), true)) {\n        throw new IOException(\"failed to create directory \" + target);\n      }\n      // create chains\n      int chain = 0;\n      boolean copyError = false;\n      for (LocatedBlock lBlk : blocks.getLocatedBlocks()) {\n        LocatedBlock lblock = lBlk;\n        DatanodeInfo[] locs = lblock.getLocations();\n        if (locs == null || locs.length == 0) {","sourceCodeStart":983,"sourceCodeEnd":1019,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NamenodeFsck.java#L983-L1019","documentation":"Error \"failed to initialize lost+found\" thrown in apache/hadoop.","triggerScenarios":"fsck cannot create or initialize the lost+found directory for corrupted files.","commonSituations":"Running 'hdfs fsck / -move' in safemode or with a user lacking write permission at root.","solutions":["Ensure the fsck user has permission to create /lost+found and that the NameNode is out of safemode, then re-run fsck with -move."],"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-22T20:17:22.307Z"}