{"record":{"id":"17354a21904b3675","repo":"apache/hadoop","slug":"f-tostring","errorCode":null,"errorMessage":"f.toString()","messagePattern":"f\\.toString\\(\\)","errorType":"exception","errorClass":"FileNotFoundException","httpStatus":null,"severity":"error","filePath":"hadoop-cloud-storage-project/hadoop-bos/src/main/java/org/apache/hadoop/fs/bos/BaiduBosFileSystem.java","lineNumber":698,"sourceCode":"      key = pathToKey(f) + FOLDER_SUFFIX;\n    }\n\n    store.storeEmptyFile(key, this.store.getEnvUserName(),\n        this.store.getEnvGroupName());\n    return true;\n  }\n\n  @Override\n  public FSDataInputStream open(Path f, int bufferSize)\n      throws IOException {\n    Path absolutePath = makeAbsolute(f);\n    String key = pathToKey(absolutePath);\n\n    FileMetadata fileMetaData = null;\n    try {\n      fileMetaData = store.retrieveMetadata(key);\n    } catch (FileNotFoundException ignore) {\n      throw new FileNotFoundException(f.toString());\n    }\n\n    if (fileMetaData.isFolder()) {\n      throw new FileNotFoundException(\"Can not open a folder\");\n    }\n\n    BosInputStream bosFsInputStream = new BosInputStream(\n        key, fileMetaData, this.store, this.statistics);\n\n    bosFsInputStream.setReadahead(this.readAhead);\n    return new FSDataInputStream(\n        new BufferedFSInputStream(\n            bosFsInputStream, this.readBufferSize));\n  }\n\n  private void createParent(Path path) throws IOException {\n    Path parent = path.getParent();\n    if (parent != null) {","sourceCodeStart":680,"sourceCodeEnd":716,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-cloud-storage-project/hadoop-bos/src/main/java/org/apache/hadoop/fs/bos/BaiduBosFileSystem.java#L680-L716","documentation":"TypedBytesWritableInput.readWritable(Writable writable) decodes a typed-bytes WRITABLE (code 50) record: the payload carries the source class name plus its serialized fields. When you pass a non-null reuse object whose class name differs from the name embedded in the payload, it throws IOException 'wrong Writable class given'. Passing null is supported — the reader reflectively instantiates the recorded class via conf.getClassByName.","triggerScenarios":"Calling readWritable(w) with a reuse object of class X while the stream's next WRITABLE record was written from class Y (e.g. WritableComparator-cached or pooled objects of a fixed type reused across heterogeneous records).","commonSituations":"Object-reuse optimizations in custom RecordReaders where one Writable instance is recycled for many records; streams where different Writable classes are interleaved; renaming/moving the writer-side Writable class so getName() no longer matches on the reader side.","solutions":["Pass null and let the reader instantiate the correct class per record (costlier but always type-safe).","Or only reuse an object when writable.getClass().getName().equals(expectedName); otherwise allocate fresh.","Keep the Writable class name stable across writer and reader deployments — avoid renaming/moving the class between versions.","Ensure the recorded class is on the reader's classpath when using null reuse, or ClassNotFoundException surfaces as IOException."],"exampleFix":"// before\nMyFixedWritable reuse = new MyFixedWritable();\nwhile (nextKeyValues()) {\n  reader.readWritable(reuse); // throws when record's class != MyFixedWritable\n}\n\n// after\nWritable w = reader.readWritable(null); // instantiate from embedded class name","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"static boolean matchesRecordClass(Writable reuse, String embeddedClassName) {\n  return reuse == null || reuse.getClass().getName().equals(embeddedClassName);\n}","tryCatchPattern":"try {\n  Writable w = tbIn.readWritable(reuse);\n} catch (IOException e) {\n  if (\"wrong Writable class given\".equals(e.getMessage())) {\n    w = tbIn.readWritable(null); // retry once, instantiating the embedded class\n  } else throw e;\n}","preventionTips":["Pass null (or a type-checked reuse object) when records may vary in class.","Keep Writable class names identical on writer and reader deployments.","Ensure the embedded class is on the reader classpath for reflective instantiation."],"tags":["hadoop","typedbytes","writable","type-mismatch","serialization"],"backgroundTag":"type-mismatch","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}