{"record":{"id":"92ee1e1d6a59f0a4","repo":"languagetool-org/languagetool","slug":"malformedurlexception-for-decommunization-url","errorCode":null,"errorMessage":"MalformedURLException for decommunization URL","messagePattern":"MalformedURLException for decommunization URL","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"languagetool-language-modules/uk/src/main/java/org/languagetool/rules/uk/SimpleReplaceRenamedRule.java","lineNumber":56,"sourceCode":"import org.languagetool.tagging.uk.PosTagHelper;\n\n/**\n * A rule that matches proper names that has been renamed\n * Loads the relevant words from <code>rules/uk/replace_renamed.txt</code>.\n * \n * @author Andriy Rysin\n */\npublic class SimpleReplaceRenamedRule extends Rule {\n\n  private static final Map<String, List<String>> RENAMED_LIST = ExtraDictionaryLoader.loadLists(\"/uk/replace_renamed.txt\");\n  private static final Pattern GEO_POSTAG_PATTERN = Pattern.compile(\"noun:inanim.*?:prop.*|adj.*\");\n  private static final URL DECOMUNIZATION_URL = createUrl();\n\n  private static URL createUrl() {\n    try {\n      return URI.create(\"https://uk.wikipedia.org/wiki/%D0%A1%D0%BF%D0%B8%D1%81%D0%BE%D0%BA_%D1%82%D0%BE%D0%BF%D0%BE%D0%BD%D1%96%D0%BC%D1%96%D0%B2_%D0%A3%D0%BA%D1%80%D0%B0%D1%97%D0%BD%D0%B8,_%D0%BF%D0%B5%D1%80%D0%B5%D0%B9%D0%BC%D0%B5%D0%BD%D0%BE%D0%B2%D0%B0%D0%BD%D0%B8%D1%85_%D0%B2%D0%BD%D0%B0%D1%81%D0%BB%D1%96%D0%B4%D0%BE%D0%BA_%D0%B4%D0%B5%D0%BA%D0%BE%D0%BC%D1%83%D0%BD%D1%96%D0%B7%D0%B0%D1%86%D1%96%D1%97\").toURL();\n    } catch (MalformedURLException e) {\n      throw new RuntimeException(e);\n    }\n  }\n\n  public SimpleReplaceRenamedRule(ResourceBundle messages) {\n    super(messages);\n    setLocQualityIssueType(ITSIssueType.Style);\n  }\n\n  @Override\n  public final String getId() {\n    return \"UK_SIMPLE_REPLACE_RENAMED\";\n  }\n\n  @Override\n  public String getDescription() {\n    return \"Пропозиція поточної назви для перейменованих власних назв\";\n  }\n","sourceCodeStart":38,"sourceCodeEnd":74,"githubUrl":"https://github.com/languagetool-org/languagetool/blob/2e990059ce67d5e2a0f7f7ca5d31160c6709df4b/languagetool-language-modules/uk/src/main/java/org/languagetool/rules/uk/SimpleReplaceRenamedRule.java#L38-L74","documentation":"SimpleReplaceRenamedRule statically builds a URL for the Ukrainian decommunization toponym list via URI.create(...).toURL(); a MalformedURLException is wrapped in a RuntimeException. Because it happens in a static initializer, the failure occurs at class-load time and surfaces as ExceptionInInitializerError/NoClassDefFoundError downstream.","triggerScenarios":"Class loading of SimpleReplaceRenamedRule when the hard-coded percent-encoded Wikipedia URL is malformed, or URI.create fails to parse the encoded string before toURL() is called.","commonSituations":"Editing the URL string and breaking percent-encoding (raw Cyrillic characters or unencoded commas/spaces); older JDKs with stricter URL/URI parsing; copy-paste introducing characters invalid in a URI.","solutions":["Validate the URL string with URI.create() in isolation to see the exact parse error.","Ensure all non-ASCII characters are percent-encoded (the comma and Cyrillic text must stay encoded).","Prefer creating the URI with multi-argument new URI(scheme, host, path, fragment) which encodes automatically.","If the class fails to load with ExceptionInInitializerError, check the cause for the MalformedURLException.","Pin a JDK version known to parse this URI if a JVM upgrade changed behavior."],"exampleFix":"// before\nprivate static final URL DECOMUNIZATION_URL = createUrl();\n// after\nprivate static final URL DECOMUNIZATION_URL;\nstatic {\n  try { DECOMUNIZATION_URL = createUrl(); }\n  catch (RuntimeException e) { throw new IllegalStateException(\"Bad decommunization list URL\", e); }\n}","handlingStrategy":"validation","validationCode":"try {\n  new URI(\"https\", \"uk.wikipedia.org\", \"/wiki/...\", null); // multi-arg URI validates/encodes\n} catch (URISyntaxException e) {\n  throw new IllegalStateException(\"Decommunization URL malformed\", e);\n}","typeGuard":"static boolean isValidUrl(String s) {\n  try { new URI(s).toURL(); return true; } catch (Exception e) { return false; }\n}","tryCatchPattern":"try {\n  URL url = DECOMUNIZATION_URL;\n} catch (ExceptionInInitializerError | RuntimeException e) {\n  LOG.error(\"Bad static URL in SimpleReplaceRenamedRule\", e.getCause());\n}","preventionTips":["Keep non-ASCII URL parts fully percent-encoded; never paste raw Cyrillic into URI strings","Use multi-argument URI constructors that encode automatically","Add a unit test asserting the static URL builds successfully","If a class fails to load with ExceptionInInitializerError, always inspect the cause"],"tags":["url","static-initializer","malformed-url"],"backgroundTag":"invalid-url-format","analyzedSha":"2e990059ce67d5e2a0f7f7ca5d31160c6709df4b","analyzedAt":"2026-09-06T09:20:17.015Z","contentChangedAt":"2026-09-06T09:20:17.015Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}