{"id":"230c0aa89e1af3b8","repo":"apache/kafka","slug":"klass-is-not-an-instance-of-org-apache-kafka-cli","errorCode":null,"errorMessage":"{klass} is not an instance of org.apache.kafka.clients.consumer.ConsumerPartitionAssignor","messagePattern":"(.+?) is not an instance of org\\.apache\\.kafka\\.clients\\.consumer\\.ConsumerPartitionAssignor","errorType":"exception","errorClass":"KafkaException","httpStatus":null,"severity":"error","filePath":"clients/src/main/java/org/apache/kafka/clients/consumer/ConsumerPartitionAssignor.java","lineNumber":447,"sourceCode":"                    throw new KafkaException(klass + \" ClassNotFoundException exception occurred\", classNotFound);\n                }\n            }\n\n            if (klass instanceof Class<?>) {\n                Object assignor = Utils.newInstance((Class<?>) klass);\n                if (assignor instanceof Configurable)\n                    ((Configurable) assignor).configure(configs);\n\n                if (assignor instanceof ConsumerPartitionAssignor) {\n                    String assignorName = ((ConsumerPartitionAssignor) assignor).name();\n                    if (assignorNameMap.containsKey(assignorName)) {\n                        throw new KafkaException(\"The assignor name: '\" + assignorName + \"' is used in more than one assignor: \" +\n                            assignorNameMap.get(assignorName) + \", \" + assignor.getClass().getName());\n                    }\n                    assignorNameMap.put(assignorName, assignor.getClass().getName());\n                    assignors.add((ConsumerPartitionAssignor) assignor);\n                } else {\n                    throw new KafkaException(klass + \" is not an instance of \" + ConsumerPartitionAssignor.class.getName());\n                }\n            } else {\n                throw new KafkaException(\"List contains element of type \" + klass.getClass().getName() + \", expected String or Class\");\n            }\n        }\n        return assignors;\n    }\n\n}\n","sourceCodeStart":429,"sourceCodeEnd":457,"githubUrl":"https://github.com/apache/kafka/blob/c31c9215e131f8c17e79f8901b48c13ee6aa8e7a/clients/src/main/java/org/apache/kafka/clients/consumer/ConsumerPartitionAssignor.java#L429-L457","documentation":"Thrown when an entry of partition.assignment.strategy loads successfully (as a String class name or a Class) but the instantiated object does not implement ConsumerPartitionAssignor. The assignor list only accepts objects the consumer can drive through the partition assignment contract.","triggerScenarios":"Passing a fully-qualified class name in partition.assignment.strategy that resolves to a producer interceptor, serializer, or any class that is not a ConsumerPartitionAssignor; passing a Class<?> literal of the wrong type.","commonSituations":"Copy-paste errors putting ConsumerInterceptor or ProducerPartitionAssignor-like class names into the strategy list; misreading docs and supplying a class name from another framework (e.g. a Connect connector class); shaded class relocation pointing at the wrong class.","solutions":["Verify every entry in partition.assignment.strategy is a class implementing org.apache.kafka.clients.consumer.ConsumerPartitionAssignor (e.g. RangeAssignor, CooperativeStickyAssignor).","Correct the typo'd class name or replace it with a built-in assignor class name.","If using a custom assignor, confirm it declares `implements ConsumerPartitionAssignor` and the fully-qualified name in config matches the compiled class."],"exampleFix":"// before\nprops.put(ConsumerConfig.PARTITION_ASSIGNMENT_STRATEGY_CONFIG,\n    \"org.apache.kafka.clients.producer.RoundRobinPartitioner\");\n\n// after\nprops.put(ConsumerConfig.PARTITION_ASSIGNMENT_STRATEGY_CONFIG,\n    \"org.apache.kafka.clients.consumer.RoundRobinAssignor\");","handlingStrategy":"type-guard","validationCode":"// Verify each entry actually implements ConsumerPartitionAssignor before it reaches the consumer\nList<Class<?>> safe = new ArrayList<>();\nfor (Object entry : assignorList) {\n    Class<?> c = (entry instanceof String) ? Class.forName((String) entry) : (Class<?>) entry;\n    if (!ConsumerPartitionAssignor.class.isAssignableFrom(c)) {\n        throw new IllegalArgumentException(c.getName() + \" is not a ConsumerPartitionAssignor; check partition.assignment.strategy\");\n    }\n    safe.add(c);\n}","typeGuard":"static boolean isAssignor(Object entry) throws ClassNotFoundException {\n    Class<?> c = (entry instanceof String) ? Class.forName((String) entry) : (Class<?>) entry;\n    return ConsumerPartitionAssignor.class.isAssignableFrom(c);\n}","tryCatchPattern":"try {\n    new KafkaConsumer<>(props);\n} catch (KafkaException e) {\n    if (e.getMessage() != null && e.getMessage().contains(\"is not an instance of\")) {\n        // strip the offending class from partition.assignment.strategy and rebuild props\n    }\n    throw e;\n}","preventionTips":["partition.assignment.strategy only accepts fully-qualified class names (Strings) or Class objects that implement ConsumerPartitionAssignor.","For custom assignors, declare `implements ConsumerPartitionAssignor` explicitly rather than a sibling interface.","Treat a typo in the class name as a likely cause: it loads a class that exists but is not an assignor."],"tags":["consumer","partition-assignor","configuration","class-loading"],"analyzedSha":"c31c9215e131f8c17e79f8901b48c13ee6aa8e7a","analyzedAt":"2026-08-03T12:34:05.770Z","schemaVersion":2}