{"record":{"id":"bf611bf9a19aafc4","repo":"apache/hadoop","slug":"resource","errorCode":null,"errorMessage":"${resource}","messagePattern":"\\$\\{resource\\}","errorType":"exception","errorClass":"FileNotFoundException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/JsonSerialization.java","lineNumber":220,"sourceCode":"      IOException {\n    writeJsonAsBytes(instance, Files.newOutputStream(file.toPath()));\n  }\n\n  /**\n   * Convert from a JSON file.\n   * @param resource input file\n   * @return the parsed JSON\n   * @throws IOException IO problems\n   * @throws JsonParseException If the input is not well-formatted\n   * @throws JsonMappingException failure to map from the JSON to this class\n   */\n  @SuppressWarnings({\"IOResourceOpenedButNotSafelyClosed\"})\n  public synchronized T fromResource(String resource)\n      throws IOException, JsonParseException, JsonMappingException {\n    try (InputStream resStream = this.getClass()\n        .getResourceAsStream(resource)) {\n      if (resStream == null) {\n        throw new FileNotFoundException(resource);\n      }\n      return mapper.readValue(resStream, classType);\n    } catch (IOException e) {\n      LOG.error(\"Exception while parsing json resource {}\", resource, e);\n      throw e;\n    }\n  }\n\n  /**\n   * clone by converting to JSON and back again.\n   * This is much less efficient than any Java clone process.\n   * @param instance instance to duplicate\n   * @return a new instance\n   * @throws IOException IO problems.\n   */\n  public T fromInstance(T instance) throws IOException {\n    return fromJson(toJson(instance));\n  }","sourceCodeStart":202,"sourceCodeEnd":238,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/JsonSerialization.java#L202-L238","documentation":"fromResource(String) reads JSON from the classpath via getResourceAsStream; when the lookup returns null the resource is not present under that name on any classpath element, and it throws FileNotFoundException carrying the raw resource string. The pre-check separates 'resource not on classpath' from stream read or parse errors.","triggerScenarios":"fromResource(\"/schema.json\") when no schema.json exists at that classpath location: wrong leading-slash convention (absolute vs package-relative), case mismatch, the resource being filtered out of the packaged jar, or a jar version that dropped it.","commonSituations":"Shade/fat-jar builds excluding resource files; resource present only on the test classpath; a module refactor moved the resource but not the constant; case-sensitive filesystems exposing a case typo.","solutions":["Verify the name resolves - check getClass().getResource(resource) != null - and mind the leading '/' (absolute) vs none (package-relative).","List the packaged jar (unzip -l) to confirm the resource was included at the expected path.","Fix the build (shade filters / resource includes) or move the resource into a module that ships on the runtime classpath."],"exampleFix":"// before\nMyType t = serializer.fromResource(\"/schema.json\"); // may not be in the jar\n\n// after\ntry (InputStream in = getClass().getResourceAsStream(\"/schema.json\")) {\n  if (in == null) {\n    throw new IllegalStateException(\"schema.json missing from classpath/jar\");\n  }\n  ...\n}","handlingStrategy":"validation","validationCode":"if (getClass().getResource(resource) == null) {\n  throw new IllegalStateException(\n      \"Resource not on classpath: \" + resource + \" - check jar contents\");\n}\nreturn serializer.fromResource(resource);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use the same resource string for a getResource probe in tests so packaging breaks surface in CI.","After adding resources, verify the packaged artifact with unzip -l or jar tf."],"tags":["json","classpath","packaging","hadoop-common"],"backgroundTag":"classpath-resource-not-found","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}