SonarSource/sonarqube · error · UnsupportedOperationException

I18n classloader does support only resources, but not classe

Error message

I18n classloader does support only resources, but not classes

What it means

Guard in I18nClassloader.loadClass: this classloader deliberately aggregates only resources (L10n bundles) from plugin classloaders and is never meant to define classes, so any attempt to load a class through it (instead of only getResource) hits this UnsupportedOperationException. It indicates code is using the loader as a full classloader rather than a resource-only view.

Source

Thrown at sonar-core/src/main/java/org/sonar/core/i18n/I18nClassloader.java:61

  I18nClassloader(List<ClassLoader> pluginClassloaders) {
    super(new URL[0]);
    this.pluginClassloaders = pluginClassloaders.toArray(new ClassLoader[pluginClassloaders.size()]);
  }

  @Override
  public URL getResource(String name) {
    for (ClassLoader pluginClassloader : pluginClassloaders) {
      URL url = pluginClassloader.getResource(name);
      if (url != null) {
        return url;
      }
    }
    return getClass().getClassLoader().getResource(name);
  }

  @Override
  protected synchronized Class loadClass(String s, boolean b) throws ClassNotFoundException {
    throw new UnsupportedOperationException("I18n classloader does support only resources, but not classes");
  }

  @Override
  public String toString() {
    return "i18n-classloader";
  }

  private static List<ClassLoader> allPluginClassloaders(PluginRepository pluginRepository) {
    // accepted limitation: some plugins extend base plugins, sharing the same classloader, so
    // there may be duplicated classloaders in the list.
    List<ClassLoader> list = Lists.newArrayList();
    for (PluginInfo info : pluginRepository.getPluginInfos()) {
      Plugin plugin = pluginRepository.getPluginInstance(info.getKey());
      list.add(plugin.getClass().getClassLoader());
    }
    list.add(I18nClassloader.class.getClassLoader());
    return list;
  }

View on GitHub (pinned to 184c821202)

Solutions

  1. Do not use I18nClassloader for class loading; use the platform/plugin classloader instead
  2. Only use it via getResource/getResources for i18n bundles
  3. Refactor calling code to fetch resources, not classes

Example fix

// before
Class<?> c = i18nClassloader.loadClass("org.sonar.Foo");
// after
Class<?> c = platformClassloader.loadClass("org.sonar.Foo");
Defensive patterns

Strategy: type-guard

Validate before calling

if (classloader instanceof I18nClassloader) {
  throw new IllegalStateException("Use platform classloader for classes");
}
Class<?> c = classloader.loadClass(name);

Type guard

boolean supportsClassLoading(ClassLoader cl) {
  return !(cl instanceof I18nClassloader);
}

Try / catch

try {
  return classloader.loadClass(name);
} catch (UnsupportedOperationException e) {
  return platformClassloader.loadClass(name);
}

Prevention

When it happens

Trigger: Attempting to load a class through this classloader, e.g. passing it to APIs that resolve classes (Class.forName-style usage, serialization frameworks, reflection helpers).

Common situations: Handing the i18n classloader to plugin managers or DI containers that expect a full classloader; debugging code that enumerates classes from all classloaders.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


AI-assisted analysis of SonarSource/sonarqube@184c821202 (2026-09-09). Data as JSON: /api/errors/3c69930e0a4020ab. Report an issue: GitHub.