stanfordnlp/CoreNLP · error · RuntimeException

java.net.MalformedURLException

Error message

java.net.MalformedURLException

What it means

In init(), URLs for 'file' and 'url' pathtypes are built with new URL(...), which throws MalformedURLException for malformed strings. init() catches it and rethrows as a RuntimeException with the original exception as cause, aborting holiday manager initialization.

Solutions

  1. Fix the configured path/URL: URL-encode spaces (%20) and use forward slashes for file paths.
  2. For local files use pathtype=classpath when the file is on the classpath, avoiding URL construction entirely.
  3. Check the exception's cause message to see the exact offending URL string and correct it in the properties.

Example fix

// before
props.setProperty("holidays.pathtype", "file");
props.setProperty("holidays.path", "C:\temp\holidays.xml");
// after
props.setProperty("holidays.pathtype", "file");
props.setProperty("holidays.path", "C:/temp/holidays.xml"); // or URL-encode: C:/temp/my%20holidays.xml
Defensive patterns

Strategy: validation

Validate before calling

try { new URL(pathOrUrl); } catch (MalformedURLException e) {
  throw new IllegalArgumentException("Invalid holiday path/URL: " + pathOrUrl, e);
}

Try / catch

try {
  holidays.init(prefix, props);
} catch (RuntimeException e) {
  if (e.getCause() instanceof MalformedURLException) {
    logger.severe("Malformed holiday URL: " + e.getCause().getMessage());
  }
  throw e;
}

Prevention

When it happens

Trigger: Configuring pathtype=file with a path that produces an invalid file URL (illegal characters like spaces/backslashes), or pathtype=url with a string that is not a syntactically valid absolute URL (missing protocol, bad characters).

Common situations: Windows-style paths ('C:\holidays.xml') used as file paths; URLs copied with surrounding quotes or spaces; protocol typos like 'htp://'; unencoded spaces in http URLs.

Understand the failure class

Background: "Invalid URL" errors: why new URL(), URI.parse, and reqwest::Url reject your string — missing scheme, whitespace, and bad path format — this error's family across 39 libraries.

Related errors


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

Appendix: source

Thrown at src/edu/stanford/nlp/time/JollyDayHolidays.java:59

    varPrefix = props.getProperty(prefix + "prefix", varPrefix);
    logger.info("Initializing JollyDayHoliday for SUTime from " + xmlPathType + ' ' + xmlPath + " as " + prefix);
    Properties managerProps = new Properties();
    managerProps.setProperty("manager.impl", "edu.stanford.nlp.time.JollyDayHolidays$MyXMLManager");
    try {
      URL holidayXmlUrl;
      if (xmlPathType.equalsIgnoreCase("classpath")) {
        holidayXmlUrl = getClass().getClassLoader().getResource(xmlPath);
      } else if (xmlPathType.equalsIgnoreCase("file")) {
        holidayXmlUrl = new URL("file:///" + xmlPath);
      } else if (xmlPathType.equalsIgnoreCase("url")) {
        holidayXmlUrl = new URL(xmlPath);
      } else {
        throw new IllegalArgumentException("Unsupported " + prefix + "pathtype = " + xmlPathType);
      }
      UrlManagerParameter ump = new UrlManagerParameter(holidayXmlUrl, managerProps);
      holidayManager = HolidayManager.getInstance(ump);
    } catch (java.net.MalformedURLException e) {
      throw new RuntimeException(e);
    }
    if (!(holidayManager instanceof MyXMLManager)) {
      throw new AssertionError("Did not get back JollyDayHolidays$MyXMLManager");
    }
    Configuration config = ((MyXMLManager) holidayManager).getConfiguration();
    holidays = getAllHolidaysMap(config);
  }

  @Override
  public void bind(Env env) {
    if (holidays != null) {
      for (Map.Entry<String, JollyHoliday> holidayEntry : holidays.entrySet()) {
        JollyHoliday jh = holidayEntry.getValue();
        env.bind(varPrefix + holidayEntry.getKey(), jh);
      }
    }
  }

View on GitHub (pinned to 1b7edd19c4)