{"record":{"id":"3315582094c7e5d7","repo":"stanfordnlp/CoreNLP","slug":"java-net-malformedurlexception","errorCode":null,"errorMessage":"java.net.MalformedURLException","messagePattern":"java\\.net\\.MalformedURLException","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/time/JollyDayHolidays.java","lineNumber":59,"sourceCode":"    varPrefix = props.getProperty(prefix + \"prefix\", varPrefix);\n    logger.info(\"Initializing JollyDayHoliday for SUTime from \" + xmlPathType + ' ' + xmlPath + \" as \" + prefix);\n    Properties managerProps = new Properties();\n    managerProps.setProperty(\"manager.impl\", \"edu.stanford.nlp.time.JollyDayHolidays$MyXMLManager\");\n    try {\n      URL holidayXmlUrl;\n      if (xmlPathType.equalsIgnoreCase(\"classpath\")) {\n        holidayXmlUrl = getClass().getClassLoader().getResource(xmlPath);\n      } else if (xmlPathType.equalsIgnoreCase(\"file\")) {\n        holidayXmlUrl = new URL(\"file:///\" + xmlPath);\n      } else if (xmlPathType.equalsIgnoreCase(\"url\")) {\n        holidayXmlUrl = new URL(xmlPath);\n      } else {\n        throw new IllegalArgumentException(\"Unsupported \" + prefix + \"pathtype = \" + xmlPathType);\n      }\n      UrlManagerParameter ump = new UrlManagerParameter(holidayXmlUrl, managerProps);\n      holidayManager = HolidayManager.getInstance(ump);\n    } catch (java.net.MalformedURLException e) {\n      throw new RuntimeException(e);\n    }\n    if (!(holidayManager instanceof MyXMLManager)) {\n      throw new AssertionError(\"Did not get back JollyDayHolidays$MyXMLManager\");\n    }\n    Configuration config = ((MyXMLManager) holidayManager).getConfiguration();\n    holidays = getAllHolidaysMap(config);\n  }\n\n  @Override\n  public void bind(Env env) {\n    if (holidays != null) {\n      for (Map.Entry<String, JollyHoliday> holidayEntry : holidays.entrySet()) {\n        JollyHoliday jh = holidayEntry.getValue();\n        env.bind(varPrefix + holidayEntry.getKey(), jh);\n      }\n    }\n  }\n","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/time/JollyDayHolidays.java#L41-L77","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","solutions":["Fix the configured path/URL: URL-encode spaces (%20) and use forward slashes for file paths.","For local files use pathtype=classpath when the file is on the classpath, avoiding URL construction entirely.","Check the exception's cause message to see the exact offending URL string and correct it in the properties."],"exampleFix":"// before\nprops.setProperty(\"holidays.pathtype\", \"file\");\nprops.setProperty(\"holidays.path\", \"C:\\temp\\holidays.xml\");\n// after\nprops.setProperty(\"holidays.pathtype\", \"file\");\nprops.setProperty(\"holidays.path\", \"C:/temp/holidays.xml\"); // or URL-encode: C:/temp/my%20holidays.xml","handlingStrategy":"validation","validationCode":"try { new URL(pathOrUrl); } catch (MalformedURLException e) {\n  throw new IllegalArgumentException(\"Invalid holiday path/URL: \" + pathOrUrl, e);\n}","typeGuard":null,"tryCatchPattern":"try {\n  holidays.init(prefix, props);\n} catch (RuntimeException e) {\n  if (e.getCause() instanceof MalformedURLException) {\n    logger.severe(\"Malformed holiday URL: \" + e.getCause().getMessage());\n  }\n  throw e;\n}","preventionTips":["URL-encode spaces and special characters in file/http paths","Prefer classpath pathtype for bundled holiday XML","Use forward slashes for cross-platform file paths"],"tags":["url","configuration","initialization"],"backgroundTag":"invalid-url-format","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"}