{"record":{"id":"606af8ff61d93ac1","repo":"pinpoint-apm/pinpoint","slug":"unexpected-invoke-count","errorCode":null,"errorMessage":"unexpected {} invoke count {}","messagePattern":"unexpected (.+?) invoke count (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"agent-module/profiler-optional/profiler-optional-jdk8/src/main/java/com/navercorp/pinpoint/profiler/instrument/lambda/LambdaFactoryClassAdaptor.java","lineNumber":72,"sourceCode":"            return new LambdaClassJava8();\n        }\n    }\n\n    public byte[] transform(byte[] bytes, LambdaClass lambdaClass) {\n        Objects.requireNonNull(bytes, \"bytes\");\n\n        final ClassReader reader = new ClassReader(bytes);\n        final ClassWriter writer = new ClassWriter(reader, ClassWriter.COMPUTE_FRAMES);\n        final List<MethodInsn> methodInsnList = lambdaClass.getMethodInsnList();\n        final MethodInstReplacer methodInstReplacer = new MethodInstReplacer(writer, methodInsnList);\n        reader.accept(methodInstReplacer, 0);\n\n        if (!LAMBDA_FACTORY_CLASS_NAME.equals(methodInstReplacer.getClassName())) {\n            throw new IllegalArgumentException(\"unexpected class \" + methodInstReplacer.getClassName());\n        }\n\n        if (methodInstReplacer.getTransformCount() != 1) {\n            logger.warn(\"unexpected {} invoke count {}\", methodInsnList, methodInstReplacer.getTransformCount());\n            // dump bytecode\n        }\n        return writer.toByteArray();\n    }\n}\n","sourceCodeStart":54,"sourceCodeEnd":78,"githubUrl":"https://github.com/pinpoint-apm/pinpoint/blob/744c3d3075e595656abb1ae331ad2c0e4c9eb996/agent-module/profiler-optional/profiler-optional-jdk8/src/main/java/com/navercorp/pinpoint/profiler/instrument/lambda/LambdaFactoryClassAdaptor.java#L54-L78","documentation":"LambdaFactoryClassAdaptor.transform() replaces java/lang/invoke/LambdaMetafactory invocations with Pinpoint's LambdaFactory when instrumenting lambda call sites. It expects exactly one transformed invocation; if methodInstReplacer.getTransformCount() != 1, it warns 'unexpected {} invoke count {}' so the (possibly wrong) bytecode can be inspected. The class is still returned, but the lambda instrumentation may be incomplete or wrong.","triggerScenarios":"Instrumenting a class whose lambda metafactory invoke instruction count is not exactly 1 — e.g. a class with multiple lambdas, zero lambdas matched, or a bytecode pattern the replacer did not anticipate.","commonSituations":"Newer compiler output (different invokedynamic handling) targeting the JDK8 adapter; a plugin interceptor attaching to a lambda-heavy class; Pinpoint instrumentation classes that contain several lambda factories.","solutions":["Inspect the dumped/original bytecode of the failing class to count LambdaMetafactory invokes","Restrict the interceptor/transform scope so classes with multiple lambdas are excluded","Update Pinpoint to a version with multi-lambda handling for lambda instrumentation","Report the class and bytecode to Pinpoint maintainers if it triggers spuriously"],"exampleFix":"// before (transform config applying to a multi-lambda class)\ntransform(\"com/example/ManyLambdas\")\n// after (exclude)\nif (className.equals(\"com/example/ManyLambdas\")) return null; // skip lambda instrumentation","handlingStrategy":"validation","validationCode":"// count lambda factory call sites before transform; int invocations = countInvokeInstructions(bytes, \"java/lang/invoke/LambdaMetafactory\"); if (invocations != 1) skip or handle multi-lambda;","typeGuard":null,"tryCatchPattern":"try { writer = adapt(reader); } catch (Exception e) { logger.warn(\"lambda transform failed for {}, returning original bytes\", className); return null; }","preventionTips":["Limit lambda instrumentation to single-lambda classes","Test instrumentation on classes compiled by your project's compiler version","Keep Pinpoint updated for multi-lambda bytecode fixes","Log and skip rather than shipping broken bytecode for multi-lambda classes"],"tags":["bytecode","instrumentation","lambda","asm","jdk8"],"backgroundTag":"internal-invariant-violation","analyzedSha":"744c3d3075e595656abb1ae331ad2c0e4c9eb996","analyzedAt":"2026-09-07T18:48:45.289Z","contentChangedAt":"2026-09-07T18:48:45.289Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}