{"record":{"id":"adf5cdecc6fd5c88","repo":"apache/pulsar","slug":"topic-does-not-exist-and-cannot-be-auto-created","errorCode":null,"errorMessage":"Topic does not exist and cannot be auto-created","messagePattern":"Topic does not exist and cannot be auto-created","errorType":"http","errorClass":"RestException","httpStatus":412,"severity":"error","filePath":"pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/PersistentTopicsBase.java","lineNumber":2491,"sourceCode":"            return null;\n        });\n    }\n\n    private void internalCreateSubscriptionForNonPartitionedTopic(\n            AsyncResponse asyncResponse, String subscriptionName,\n            MessageIdImpl targetMessageId, boolean authoritative, boolean replicated,\n            Map<String, String> properties) {\n\n        validateTopicOwnershipAsync(topicName, authoritative)\n                .thenCompose(__ -> validateTopicOperationAsync(topicName, TopicOperation.SUBSCRIBE, subscriptionName))\n                .thenCompose(__ -> pulsar().getBrokerService().isAllowAutoTopicCreationAsync(topicName))\n                .thenCompose(isAllowAutoTopicCreation -> pulsar().getBrokerService()\n                        .getTopic(topicName.toString(), isAllowAutoTopicCreation))\n                .thenApply(optTopic -> {\n                    if (optTopic.isPresent()) {\n                        return optTopic.get();\n                    } else {\n                        throw new RestException(Status.PRECONDITION_FAILED,\n                                \"Topic does not exist and cannot be auto-created\");\n                    }\n        }).thenCompose(topic -> {\n            if (topic.getSubscriptions().containsKey(subscriptionName)) {\n                throw new RestException(Status.CONFLICT, \"Subscription already exists for topic\");\n            }\n\n            return topic.createSubscription(subscriptionName, InitialPosition.Latest, replicated, properties);\n        }).thenCompose(subscription -> {\n            // Mark the cursor as \"inactive\" as it was created without a real consumer connected\n            ((PersistentSubscription) subscription).deactivateCursor();\n            return subscription.resetCursor(\n                    PositionFactory.create(targetMessageId.getLedgerId(), targetMessageId.getEntryId()));\n        }).thenRun(() -> {\n            log.info()\n                    .attr(\"topic\", topicName)\n                    .attr(\"subscription\", subscriptionName)\n                    .attr(\"messageId\", targetMessageId)","sourceCodeStart":2473,"sourceCodeEnd":2509,"githubUrl":"https://github.com/apache/pulsar/blob/820761864ed8e2a7d2e52dd9763ad2ae117c1395/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/PersistentTopicsBase.java#L2473-L2509","documentation":"internalCreateSubscriptionForNonPartitionedTopic found the topic absent and broker configuration disallows auto-creation (isAllowAutoTopicCreationAsync returned false), so subscription creation fails with 404 because there is no topic to subscribe to.","triggerScenarios":"Thrown at pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/PersistentTopicsBase.java:2491 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Create the topic explicitly first, then create the subscription","Enable topic auto-creation on the namespace/broker if that matches your policy"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"820761864ed8e2a7d2e52dd9763ad2ae117c1395","analyzedAt":"2026-09-06T00:14:20.138Z","contentChangedAt":"2026-09-06T00:14:20.138Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}