{"record":{"id":"9a704ad0f20a752c","repo":"pinpoint-apm/pinpoint","slug":"not-found-template-class-resource","errorCode":null,"errorMessage":"not found template class resource ","messagePattern":"not found template class resource ","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"agent-module/profiler/src/main/java/com/navercorp/pinpoint/profiler/instrument/ASMGuardedInterceptorFactory.java","lineNumber":281,"sourceCode":"        final String concreteInternalName = Type.getInternalName(delegateClass);\n\n        final Map<String, String> mapping = new HashMap<>();\n        mapping.put(Type.getInternalName(template), newInternalName);\n        mapping.put(baseInterfaceInternalName, concreteInternalName);\n\n        final ClassReader classReader = new ClassReader(templateBytes);\n        // COMPUTE_MAXS: instructions are unchanged, but descriptors change length. EXPAND_FRAMES\n        // because the remapper requires expanded frames to retype their entries.\n        final ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_MAXS);\n        final ClassRemapper remapper = new RetypingClassRemapper(classWriter, new SimpleRemapper(mapping), concreteInternalName);\n        classReader.accept(remapper, ClassReader.EXPAND_FRAMES);\n        return classWriter.toByteArray();\n    }\n\n    private static byte[] readTemplateBytes(Class<?> template) throws IOException {\n        final InputStream inputStream = openTemplateStream(template);\n        if (inputStream == null) {\n            throw new IOException(\"not found template class resource \" + template.getName());\n        }\n        try {\n            return IOUtils.toByteArray(inputStream);\n        } finally {\n            inputStream.close();\n        }\n    }\n\n    private static InputStream openTemplateStream(Class<?> template) {\n        final InputStream inputStream = template.getResourceAsStream(template.getSimpleName() + \".class\");\n        if (inputStream != null) {\n            return inputStream;\n        }\n        final BootstrapCore bootstrapCore = templateSource;\n        if (bootstrapCore != null) {\n            final String resourceName = JavaAssistUtils.javaNameToJvmName(template.getName()) + \".class\";\n            return bootstrapCore.openStream(resourceName);\n        }","sourceCodeStart":263,"sourceCodeEnd":299,"githubUrl":"https://github.com/pinpoint-apm/pinpoint/blob/744c3d3075e595656abb1ae331ad2c0e4c9eb996/agent-module/profiler/src/main/java/com/navercorp/pinpoint/profiler/instrument/ASMGuardedInterceptorFactory.java#L263-L299","documentation":"ASMGuardedInterceptorFactory.readTemplateBytes() opens the class resource for a template class; if openTemplateStream() returns null the template class resource cannot be located on the classpath, and an IOException is thrown. The factory needs the template bytecode to rewrite interceptor templates; without it weaving cannot continue.","triggerScenarios":"rewriteTemplate calls readTemplateBytes for a template Class whose .class resource cannot be obtained as a stream (openTemplateStream returns null).","commonSituations":"Template class not present in the jar; template class generated/renamed; classloader cannot return the resource (special classloaders, shaded jars); packaging stripped class files.","solutions":["Ensure the template class file is packaged in the plugin jar","Check which classloader is used to open the resource and verify visibility","Rebuild/redeploy the plugin jar if class files were stripped by the build (e.g. shading exclusions)","Log the template class name and verify with jar tf that the resource exists"],"exampleFix":"// build fix: keep class resources in shade plugin\n// before\n<exclude>**/template/**</exclude>\n// after\n<!-- remove the exclusion so template classes ship in the jar -->","handlingStrategy":"fallback","validationCode":"// Verify the template resource is resolvable before weaving\nif (template.getClassLoader().getResource(template.getName().replace('.', '/') + \".class\") == null) {\n    throw new IllegalStateException(\"template class resource missing: \" + template.getName());\n}","typeGuard":null,"tryCatchPattern":"try {\n    factory.newInterceptor(...);\n} catch (IOException e) {\n    logger.error(\"template resource missing: {}\", e.getMessage());\n}","preventionTips":["Keep template classes inside the shipped plugin jar","Check shading/exclusion rules in the build that could strip .class resources","Verify jar contents with jar tf before deployment"],"tags":["java","classpath","resource"],"backgroundTag":"file-not-found","analyzedSha":"744c3d3075e595656abb1ae331ad2c0e4c9eb996","analyzedAt":"2026-09-07T18:48:45.289Z","contentChangedAt":"2026-09-07T18:48:45.289Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}