languagetool-org/languagetool · error · RuntimeException

MalformedURLException for decommunization URL

Error message

MalformedURLException for decommunization URL

What it means

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.

Source

Thrown at languagetool-language-modules/uk/src/main/java/org/languagetool/rules/uk/SimpleReplaceRenamedRule.java:56

import org.languagetool.tagging.uk.PosTagHelper;

/**
 * A rule that matches proper names that has been renamed
 * Loads the relevant words from <code>rules/uk/replace_renamed.txt</code>.
 * 
 * @author Andriy Rysin
 */
public class SimpleReplaceRenamedRule extends Rule {

  private static final Map<String, List<String>> RENAMED_LIST = ExtraDictionaryLoader.loadLists("/uk/replace_renamed.txt");
  private static final Pattern GEO_POSTAG_PATTERN = Pattern.compile("noun:inanim.*?:prop.*|adj.*");
  private static final URL DECOMUNIZATION_URL = createUrl();

  private static URL createUrl() {
    try {
      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();
    } catch (MalformedURLException e) {
      throw new RuntimeException(e);
    }
  }

  public SimpleReplaceRenamedRule(ResourceBundle messages) {
    super(messages);
    setLocQualityIssueType(ITSIssueType.Style);
  }

  @Override
  public final String getId() {
    return "UK_SIMPLE_REPLACE_RENAMED";
  }

  @Override
  public String getDescription() {
    return "Пропозиція поточної назви для перейменованих власних назв";
  }

View on GitHub (pinned to 2e990059ce)

Solutions

  1. Validate the URL string with URI.create() in isolation to see the exact parse error.
  2. Ensure all non-ASCII characters are percent-encoded (the comma and Cyrillic text must stay encoded).
  3. Prefer creating the URI with multi-argument new URI(scheme, host, path, fragment) which encodes automatically.
  4. If the class fails to load with ExceptionInInitializerError, check the cause for the MalformedURLException.
  5. Pin a JDK version known to parse this URI if a JVM upgrade changed behavior.

Example fix

// before
private static final URL DECOMUNIZATION_URL = createUrl();
// after
private static final URL DECOMUNIZATION_URL;
static {
  try { DECOMUNIZATION_URL = createUrl(); }
  catch (RuntimeException e) { throw new IllegalStateException("Bad decommunization list URL", e); }
}
Defensive patterns

Strategy: validation

Validate before calling

try {
  new URI("https", "uk.wikipedia.org", "/wiki/...", null); // multi-arg URI validates/encodes
} catch (URISyntaxException e) {
  throw new IllegalStateException("Decommunization URL malformed", e);
}

Type guard

static boolean isValidUrl(String s) {
  try { new URI(s).toURL(); return true; } catch (Exception e) { return false; }
}

Try / catch

try {
  URL url = DECOMUNIZATION_URL;
} catch (ExceptionInInitializerError | RuntimeException e) {
  LOG.error("Bad static URL in SimpleReplaceRenamedRule", e.getCause());
}

Prevention

When it happens

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

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

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 languagetool-org/languagetool@2e990059ce (2026-09-06). Data as JSON: /api/errors/92ee1e1d6a59f0a4. Report an issue: GitHub.