{"record":{"id":"79a05e6ba89c7d70","repo":"stanfordnlp/CoreNLP","slug":"don-t-know-how-to-get-reader-from-class-class-of","errorCode":null,"errorMessage":"don't know how to get Reader from class {class} of object {object}","messagePattern":"don't know how to get Reader from class (.+?) of object (.+?)","errorType":"exception","errorClass":"java.lang.RuntimeException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/objectbank/ReaderIteratorFactory.java","lineNumber":217,"sourceCode":"//               iter = l.iterator();\n//               file = (File) iter.next();\n//             }\n//             if (((String)o).endsWith(\".gz\")) {\n//               BufferedReader tmp = new BufferedReader(new InputStreamReader(new GZIPInputStream(new FileInputStream(file)), enc));\n//               nextObject = tmp;\n//             } else {\n//               nextObject = new BufferedReader(new EncodingFileReader(file, enc));\n//             }\n//           } else {\n            nextObject = new BufferedReader(new StringReader((String) o));\n//          }\n        } else if (o instanceof URL) {\n          // todo: add encoding specification to this as well? -akleeman\n          nextObject = new BufferedReader(new InputStreamReader(((URL) o).openStream()));\n        } else if (o instanceof Reader) {\n          nextObject = new BufferedReader((Reader) o);\n        } else {\n          throw new RuntimeException(\"don't know how to get Reader from class \" + o.getClass() + \" of object \" + o);\n        }\n      } catch (IOException e) {\n        throw new RuntimeException(e);\n      }\n    }\n\n    /**\n     * @return true if there is another (valid) input source to read from\n     */\n    @Override\n    public boolean hasNext() {\n      return nextObject != null;\n    }\n\n    /**\n     * Returns nextObject and then sets nextObject to the next input source.\n     *\n     * @return BufferedReader for next input source.","sourceCodeStart":199,"sourceCodeEnd":235,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/objectbank/ReaderIteratorFactory.java#L199-L235","documentation":"ReaderIteratorFactory.setNextObject converts each element of the supplied input collection into a Reader. It supports File, String (path), URL, InputStream, and Reader; if an element is of any other type, it throws this RuntimeException telling you the class it cannot handle.","triggerScenarios":"Passing a List/set to a ReaderIteratorFactory (or getReaderIterator) containing objects of an unsupported type, e.g. Path, URI, or a custom file-wrapper object.","commonSituations":"Java 7+ code putting java.nio.file.Path objects in the collection (only java.io.File is supported); passing URIs instead of URLs; a refactor that changed the collection's element type.","solutions":["Convert unsupported elements to java.io.File or URL before adding them: file.toFile() or uri.toURL()","Pass Strings (file paths) or Readers/InputStreams instead","Filter the collection to supported types (File, URL, String, InputStream, Reader)"],"exampleFix":"// before\ninputs.add(Paths.get(\"data.txt\"));\n// after\ninputs.add(Paths.get(\"data.txt\").toFile());","handlingStrategy":"type-guard","validationCode":"List<Object> supported = inputs.stream()\n  .map(o -> o instanceof Path ? ((Path) o).toFile() : o instanceof URI ? ((URI) o).toURL() : o)\n  .collect(Collectors.toList());","typeGuard":"boolean isSupportedInput(Object o) { return o instanceof File || o instanceof URL || o instanceof String || o instanceof InputStream || o instanceof Reader; }","tryCatchPattern":"try { it = factory.getReaderIterator(); } catch (RuntimeException e) { if (e.getMessage().startsWith(\"don't know how to get Reader from class\")) { /* normalize inputs to File/URL/String */ } else throw e; }","preventionTips":["Map java.nio.file.Path and URI objects to File/URL before adding to the collection","Document/fix the element type of the input collection","Add an assertion that all inputs pass the type guard before constructing the factory"],"tags":["java","stanford-nlp","type-mismatch","io"],"backgroundTag":"incompatible-source-type","analyzedSha":"1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a","analyzedAt":"2026-09-10T02:24:07.274Z","contentChangedAt":"2026-09-10T02:24:07.274Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}