{"record":{"id":"8d7055d14c3df8e0","repo":"elastic/elasticsearch","slug":"failed-to-load-built-in-patterns","errorCode":null,"errorMessage":"failed to load built-in patterns","messagePattern":"failed to load built-in patterns","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"critical","filePath":"libs/grok/src/main/java/org/elasticsearch/grok/GrokBuiltinPatterns.java","lineNumber":133,"sourceCode":"            \"postgresql\",\n            \"rails\",\n            \"redis\",\n            \"ruby\",\n            \"squid\",\n            \"zeek\"\n        );\n        return loadPatternsFromDirectory(patternNames, \"/patterns/ecs-v1/\");\n    }\n\n    private static PatternBank loadPatternsFromDirectory(List<String> patternNames, String directory) {\n        Map<String, String> builtinPatterns = new LinkedHashMap<>();\n        for (String pattern : patternNames) {\n            try {\n                try (InputStream is = GrokBuiltinPatterns.class.getResourceAsStream(directory + pattern)) {\n                    loadPatternsFromFile(builtinPatterns, is);\n                }\n            } catch (IOException e) {\n                throw new RuntimeException(\"failed to load built-in patterns\", e);\n            }\n        }\n        return new PatternBank(builtinPatterns);\n    }\n\n    private static void loadPatternsFromFile(Map<String, String> patternBank, InputStream inputStream) throws IOException {\n        String line;\n        BufferedReader br = new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8));\n        while ((line = br.readLine()) != null) {\n            String trimmedLine = line.replaceAll(\"^\\\\s+\", \"\");\n            if (trimmedLine.startsWith(\"#\") || trimmedLine.length() == 0) {\n                continue;\n            }\n\n            String[] parts = trimmedLine.split(\"\\\\s+\", 2);\n            if (parts.length == 2) {\n                patternBank.put(parts[0], parts[1]);\n            }","sourceCodeStart":115,"sourceCodeEnd":151,"githubUrl":"https://github.com/elastic/elasticsearch/blob/db6a809a667c081ca1dc7500389d26975573215f/libs/grok/src/main/java/org/elasticsearch/grok/GrokBuiltinPatterns.java#L115-L151","documentation":"Thrown by GrokBuiltinPatterns.loadPatternsFromDirectory() as a RuntimeException wrapping an IOException that occurred while reading a built-in pattern resource file from the classpath. The method reads pattern files from JAR resources (e.g. /patterns/legacy/grok-patterns or /patterns/ecs-v1/aws). If any file fails to load, all loading stops and this exception propagates.","triggerScenarios":"An IOException occurs while opening or reading a built-in pattern resource file via GrokBuiltinPatterns.class.getResourceAsStream(). This could be caused by: a missing resource file in the JAR (classpath issue), an I/O error reading the resource stream, or a corrupted JAR. The exception wraps the original IOException as the cause.","commonSituations":"Custom JAR packaging that excluded the /patterns/ resource directory; classloader issue in an OSGi or modular environment preventing resource loading; corrupted JAR file; security manager blocking resource access; running from an IDE where resources were not copied to the output directory.","solutions":["Inspect RuntimeException.getCause() (an IOException) for the specific I/O error.","Verify that the grok library JAR contains the /patterns/legacy/ and /patterns/ecs-v1/ resource directories — use jar tf or unzip -l.","If running from an IDE, ensure Maven/Gradle resource copying is configured (src/main/resources → target/classes).","If packaging a custom distribution, ensure the grok module's resources are included in the classpath.","Check for classloader issues in application server or modular environments that prevent getResourceAsStream from finding the resources."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    PatternBank bank = GrokBuiltinPatterns.legacyPatterns();\n} catch (RuntimeException e) {\n    if (e.getCause() instanceof IOException) {\n        // resource loading failure — check JAR contents and classpath\n        logger.error(\"Failed to load grok built-in patterns\", e);\n    }\n    throw e;\n}","preventionTips":["Verify the grok library JAR includes the /patterns/ resource directories.","In IDE builds, ensure Maven/Gradle resource copying is configured.","In custom distributions, include the grok module's resources on the classpath.","Check for classloader restrictions in modular/application server environments."],"tags":["grok","pattern-matching","resource-loading","classpath","packaging","ingest"],"analyzedSha":"db6a809a667c081ca1dc7500389d26975573215f","analyzedAt":"2026-08-12T01:39:14.192Z","schemaVersion":2},"datasetVersion":"2026-08-12T08:17:17.861Z"}