stanfordnlp/CoreNLP · warning

Error reading string

Error message

Error reading string

What it means

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.

Solutions

  1. Inspect the logged follow-up exception (log.warn(e)) for the actual IO cause
  2. If results look truncated, treat the warning as a failure and re-run with your own tag stripping
  3. Wrap the call and validate that the output is non-empty/complete before use
  4. Replace with your own regex-based stripper if this path keeps failing

Example fix

// before
String clean = XMLUtils.stripTags(raw); // silently truncated on IO error
// after
String clean = XMLUtils.stripTags(raw);
if (clean.isEmpty() && !raw.isEmpty()) {
  throw new IOException("stripTags returned empty result for non-empty input");
}
Defensive patterns

Strategy: fallback

Validate before calling

if (s == null || s.isEmpty()) throw new IllegalArgumentException("stripTags input must be non-empty");

Try / catch

String clean = XMLUtils.stripTags(raw);
if (raw != null && !raw.isEmpty() && clean.isEmpty()) {
  log.warn("stripTags produced empty output; check logs for 'Error reading string' IO cause");
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "failed to read file", EACCES, ENOENT and "could not read <path>" errors: when a program can't read a file from disk — this error's family across 49 libraries.

Related errors


AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10). Data as JSON: /api/errors/aec3606ff13878dc. Report an issue: GitHub.

Appendix: source

Thrown at src/edu/stanford/nlp/util/XMLUtils.java:374

          }
          position += text.length();
        }
        //        System.err.println(position + " got text: " + text);
        String tag = XMLUtils.readTag(r);
        if (tag == null) {
          break;
        }
        if (markLineBreaks && XMLUtils.isBreaking(parseTag(tag))) {
          result.append("\n");
          if (mapBack != null) {
            mapBack.add(Integer.valueOf(-position));
          }
        }
        position += tag.length();
        //        System.err.println(position + " got tag: " + tag);
      } while (true);
    } catch (IOException e) {
      log.warn("Error reading string");
      log.warn(e);
    }
    return result.toString();
  }

  public static boolean isBreaking(String tag) {
    return breakingTags.contains(tag);
  }

  public static boolean isBreaking(XMLTag tag) {
    return breakingTags.contains(tag.name);
  }

  /**
   * Reads all text up to next XML tag and returns it as a String.
   *
   * @return the String of the text read, which may be empty.
   */

View on GitHub (pinned to 1b7edd19c4)