{"record":{"id":"9bbab61ef863a7ae","repo":"apache/hadoop","slug":"no-uri-in-deserialized-path","errorCode":null,"errorMessage":"No URI in deserialized Path","messagePattern":"No URI in deserialized Path","errorType":"validation","errorClass":"InvalidObjectException","httpStatus":null,"severity":"critical","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/Path.java","lineNumber":615,"sourceCode":"    URI newUri = null;\n    try {\n      newUri = new URI(scheme, authority , \n        normalizePath(scheme, pathUri.getPath()), null, fragment);\n    } catch (URISyntaxException e) {\n      throw new IllegalArgumentException(e);\n    }\n    return new Path(newUri);\n  }\n\n  /**\n   * Validate the contents of a deserialized Path, so as\n   * to defend against malicious object streams.\n   * @throws InvalidObjectException if there's no URI\n   */\n  @Override\n  public void validateObject() throws InvalidObjectException {\n    if (uri == null) {\n      throw new InvalidObjectException(\"No URI in deserialized Path\");\n    }\n\n  }\n}\n","sourceCodeStart":597,"sourceCodeEnd":620,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/Path.java#L597-L620","documentation":"Path implements ObjectInputValidation and its validateObject() runs after Java native deserialization; if the uri field is null it throws InvalidObjectException. This guard exists to defend against malicious or corrupted object streams: Path's invariants (a non-null URI) must hold even when the object did not come from a constructor. Seeing it means the serialized stream was tampered with, truncated, written by incompatible code, or the field was never set.","triggerScenarios":"ObjectInputStream.readObject() on a stream containing a Path whose uri field is absent/null, deserializing Paths written by a differently-versioned Hadoop or hand-crafted streams, or interposing a readObject that leaves uri unset.","commonSituations":"RPC or MapReduce shuffle payloads deserialized after partial writes, caches (e.g. persisted DistCp/CopyFiles FilePair sequences) moved between Hadoop versions, cross-service serialization where one side serialized a Path subclass without a URI, or security testing with mutated streams.","solutions":["Verify integrity of the serialized payload: re-transfer or regenerate the stream and confirm it was produced by the same Hadoop version on both ends.","Prefer rebuilding the object: serialize the path String (path.toUri().toString()) and reconstruct with new Path(str) instead of Java object serialization of Path itself.","If streams come from an untrusted source, validate before deserializing and treat InvalidObjectException as a security signal, not a retryable glitch.","Align Hadoop versions on writer and reader so serialized class layouts match."],"exampleFix":"// before\nPath p = (Path) in.readObject(); // may yield InvalidObjectException on bad streams\n\n// after\n// send/receive the textual form instead of the Java object\nwriteUTF(p.toUri().toString());\n...\nPath p = new Path(in.readUTF());","handlingStrategy":"validation","validationCode":"// validate after deserialization instead of trusting the stream\nObject o = in.readObject();\nif (o instanceof Path) {\n  Path p = (Path) o;\n  if (p.toUri() == null) {\n    throw new InvalidObjectException(\"Path without URI\");\n  }\n}","typeGuard":null,"tryCatchPattern":"try {\n  Path p = (Path) in.readObject(); // validateObject() runs here\n} catch (InvalidObjectException e) {\n  // treat as corrupt/hostile stream: discard, do not retry\n  throw new IOException(\"Corrupt serialized Path payload\", e);\n}","preventionTips":["Serialize Path as its URI string, not as a Java object.","Treat InvalidObjectException as a data-integrity/security signal, not transient.","Pin matching Hadoop versions on both ends of any object-stream channel carrying Paths."],"tags":["hadoop","serialization","deserialization","security","invalidobjectexception","path"],"backgroundTag":"deserialization-validation-failed","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}