{"record":{"id":"aec3606ff13878dc","repo":"stanfordnlp/CoreNLP","slug":"error-reading-string","errorCode":null,"errorMessage":"Error reading string","messagePattern":"Error reading string","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/edu/stanford/nlp/util/XMLUtils.java","lineNumber":374,"sourceCode":"          }\n          position += text.length();\n        }\n        //        System.err.println(position + \" got text: \" + text);\n        String tag = XMLUtils.readTag(r);\n        if (tag == null) {\n          break;\n        }\n        if (markLineBreaks && XMLUtils.isBreaking(parseTag(tag))) {\n          result.append(\"\\n\");\n          if (mapBack != null) {\n            mapBack.add(Integer.valueOf(-position));\n          }\n        }\n        position += tag.length();\n        //        System.err.println(position + \" got tag: \" + tag);\n      } while (true);\n    } catch (IOException e) {\n      log.warn(\"Error reading string\");\n      log.warn(e);\n    }\n    return result.toString();\n  }\n\n  public static boolean isBreaking(String tag) {\n    return breakingTags.contains(tag);\n  }\n\n  public static boolean isBreaking(XMLTag tag) {\n    return breakingTags.contains(tag.name);\n  }\n\n  /**\n   * Reads all text up to next XML tag and returns it as a String.\n   *\n   * @return the String of the text read, which may be empty.\n   */","sourceCodeStart":356,"sourceCodeEnd":392,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/util/XMLUtils.java#L356-L392","documentation":"stripTags parses the tag structure of a string using an internal reader; an IOException there is caught, logged as 'Error reading string' followed by log.warn(e), and the partially built result string is returned. Although the input is a String (where IOException is theoretically impossible), the reader-based implementation forces handling it, so real failures would come from the wrapped stream. Callers get a truncated or empty result with only a log warning.","triggerScenarios":"Calling XMLUtils.stripTags(s) where the underlying reader of the string unexpectedly fails (IO error on a wrapped/character stream), producing the 'Error reading string' warning and a partial output.","commonSituations":"Passing very large strings backed by streaming readers, custom Reader implementations that throw, or defensive handling of an edge case that in practice indicates a JVM/IO layer problem rather than input content.","solutions":["Inspect the logged follow-up exception (log.warn(e)) for the actual IO cause","If results look truncated, treat the warning as a failure and re-run with your own tag stripping","Wrap the call and validate that the output is non-empty/complete before use","Replace with your own regex-based stripper if this path keeps failing"],"exampleFix":"// before\nString clean = XMLUtils.stripTags(raw); // silently truncated on IO error\n// after\nString clean = XMLUtils.stripTags(raw);\nif (clean.isEmpty() && !raw.isEmpty()) {\n  throw new IOException(\"stripTags returned empty result for non-empty input\");\n}","handlingStrategy":"fallback","validationCode":"if (s == null || s.isEmpty()) throw new IllegalArgumentException(\"stripTags input must be non-empty\");","typeGuard":null,"tryCatchPattern":"String clean = XMLUtils.stripTags(raw);\nif (raw != null && !raw.isEmpty() && clean.isEmpty()) {\n  log.warn(\"stripTags produced empty output; check logs for 'Error reading string' IO cause\");\n}","preventionTips":["Sanity-check output completeness against input length","Check the log for the follow-up exception line with the IO cause","Avoid custom Reader-backed inputs that can throw mid-read","Have a fallback tag-stripping implementation"],"tags":["xml","io","string-processing","java"],"backgroundTag":"file-read-failed","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"}