pentaho/pentaho-kettle · critical · IllegalStateException

Could not initialize from codeSnippets.xml

Error message

Could not initialize from codeSnippets.xml

What it means

Static initializer of UserDefinedJavaClassCodeSnippits fails to parse the bundled codeSnippits.xml resource and rethrows as IllegalStateException, aborting class initialization. This means the code-snippet definitions shipped with Pentaho could not be loaded from the classpath.

Solutions

  1. Verify codeSnippits.xml exists inside the kettle ui plugin jar (unzip -l) and reinstall/restore the jar if missing.
  2. Check the full stack trace for the underlying KettleXMLException cause (MalformedURLException, SAX parse error) and fix the XML file if customized.
  3. Restore a clean installation or re-extract the Pentaho distribution to replace corrupted resources.
  4. Check for duplicate/mismatched kettle-ui jars on the classpath (lib vs plugins) that shadow the resource.
Defensive patterns

Strategy: try-catch

Validate before calling

try (InputStream in = getClass().getResourceAsStream("/codeSnippits.xml")) {
  if (in == null) throw new IllegalStateException("codeSnippits.xml missing from classpath");
}

Type guard

boolean snippetResourcePresent() { return getClass().getResource("/codeSnippits.xml") != null; }

Try / catch

try { snippits = UserDefinedJavaClassCodeSnippits.getSnippitsHelper(); }
catch (Throwable t) { logger.warn("Code snippits unavailable (" + t.getMessage() + "); continuing without them"); }

Prevention

When it happens

Trigger: First access to the UserDefinedJavaClassCodeSnippits class (e.g. opening the UDJC step dialog) when codeSnippits.xml is missing from the classpath, unreadable, or fails KettleXMLException parsing inside addSnippits().

Common situations: Corrupted or incomplete Pentaho installation where ui jar resources are damaged; packaging a trimmed jar that omits codeSnippits.xml; classloader issues in embedded/custom launches of Kettle; XML modified or broken by a faulty patch.

Related errors


AI-assisted analysis of pentaho/pentaho-kettle@f3058517a1 (2026-09-13). Data as JSON: /api/errors/a1b968374bb5bc28. Report an issue: GitHub.

Appendix: source

Thrown at ui/src/main/java/org/pentaho/di/ui/trans/steps/userdefinedjavaclass/UserDefinedJavaClassCodeSnippits.java:44

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class UserDefinedJavaClassCodeSnippits {
  private static Class<?> PKG = UserDefinedJavaClass.class;
  private static final UserDefinedJavaClassCodeSnippits snippitsHelper;

  private final List<Snippit> snippits = new ArrayList<Snippit>();
  private final Map<String, Snippit> snippitsMap = new HashMap<String, Snippit>();
  private final LogChannel log = new LogChannel( "UserDefinedJavaClassCodeSnippits" );

  static {
    snippitsHelper = new UserDefinedJavaClassCodeSnippits();
    try {
      snippitsHelper.addSnippits( "codeSnippits.xml" );
    } catch ( KettleXMLException ex ) {
      throw new IllegalStateException( "Could not initialize from codeSnippets.xml" );
    }
  }

  public static UserDefinedJavaClassCodeSnippits getSnippitsHelper() throws KettleXMLException {
    return snippitsHelper;
  }

  private UserDefinedJavaClassCodeSnippits() {
  }

  public void addSnippits( String strFileName ) throws KettleXMLException {
    Document doc =
      XMLHandler.loadXMLFile(
        UserDefinedJavaClassCodeSnippits.class.getResourceAsStream( strFileName ), null, false, false );
    buildSnippitList( doc );
  }

  public enum Category {

View on GitHub (pinned to f3058517a1)