{"record":{"id":"4640bc292666b1ab","repo":"eclipse-vertx/vert.x","slug":"same-deployable-supplied-more-than-once","errorCode":null,"errorMessage":"Same deployable supplied more than once","messagePattern":"Same deployable supplied more than once","errorType":"exception","errorClass":"VertxException","httpStatus":null,"severity":"error","filePath":"vertx-core/src/main/java/io/vertx/core/impl/deployment/DefaultDeployment.java","lineNumber":54,"sourceCode":"                                             Function<Deployable, String> identifierProvider,\n                                             ClassLoader tccl,\n                                             Callable<? extends Deployable> supplier) throws Exception {\n    int numberOfInstances = options.getInstances();\n    Set<Deployable> deployables = Collections.newSetFromMap(new IdentityHashMap<>());\n    for (int i = 0; i < numberOfInstances;i++) {\n      Deployable deployable;\n      try {\n        deployable = supplier.call();\n      } catch (Exception e) {\n        throw e;\n      }\n      if (deployable == null) {\n        throw new VertxException(\"Supplied deployable is null\", true);\n      }\n      deployables.add(deployable);\n    }\n    if (deployables.size() != numberOfInstances) {\n      throw new VertxException(\"Same deployable supplied more than once\", true);\n    }\n    CloseableResource<WorkerPool> workerPool = null;\n    ThreadingModel mode = options.getThreadingModel();\n    if (mode == null) {\n      mode = ThreadingModel.EVENT_LOOP;\n    }\n    if (mode != ThreadingModel.VIRTUAL_THREAD) {\n      if (options.getWorkerPoolName() != null) {\n        workerPool = vertx.createSharedWorkerPool(options.getWorkerPoolName(), options.getWorkerPoolSize(), options.getMaxWorkerExecuteTime(), options.getMaxWorkerExecuteTimeUnit());\n      }\n    } else {\n      if (!vertx.isVirtualThreadAvailable()) {\n        throw new VertxException(\"This Java runtime does not support virtual threads\", true);\n      }\n    }\n    ArrayList<Deployable> list = new ArrayList<>(deployables);\n    return new DefaultDeployment(vertx, options, log, list, identifierProvider.apply(list.get(0)), mode, workerPool, tccl);\n  }","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/eclipse-vertx/vert.x/blob/fb308bd8c3f12c79f4ae89bef67fadf6c80d036e/vertx-core/src/main/java/io/vertx/core/impl/deployment/DefaultDeployment.java#L36-L72","documentation":"When deploying multiple instances via a Supplier, each instance must be a distinct Verticle object. Vert.x collects the instances and if the resulting list size differs from the requested instance count, it means the same deployable instance was returned more than once, so it throws VertxException('Same deployable supplied more than once'). Deploying the identical verticle instance multiple times would corrupt per-instance state.","triggerScenarios":"deployVerticle(Supplier<Verticle>, DeploymentOptions) with setInstances(n > 1) where the supplier returns the same singleton Verticle object every time (e.g. a cached instance or a method returning a shared field).","commonSituations":"Returning a singleton verticle from a factory while requesting several instances; caching/memoizing the verticle construction; DI singleton scope combined with instances > 1.","solutions":["Make the supplier create a new Verticle instance on every invocation","If you want multiple instances, use new MyVerticle() per call rather than a shared field","Set instances to 1 if you truly intend to deploy a single shared object"],"exampleFix":"// before\nMyVerticle v = new MyVerticle();\nvertx.deployVerticle(() -> v, new DeploymentOptions().setInstances(3)); // same instance thrice\n// after\nvertx.deployVerticle(MyVerticle::new, new DeploymentOptions().setInstances(3)); // fresh instance each call","handlingStrategy":"validation","validationCode":"Set<Verticle> seen = Collections.newSetFromMap(new IdentityHashMap<>());\n// inside supplier:\nVerticle v = create();\nif (!seen.add(v)) throw new IllegalStateException(\"supplier reused verticle instance\");","typeGuard":null,"tryCatchPattern":"try {\n  vertx.deployVerticle(sup, opts);\n} catch (VertxException e) {\n  // supplier returned the same instance for multiple instances\n}","preventionTips":["Use a constructor/method reference (MyVerticle::new) as the supplier","Never memoize or cache verticle instances for multi-instance deployments","Keep DI scope prototype for verticle suppliers with instances > 1"],"tags":["deployment","verticle","supplier","duplicate-instance"],"backgroundTag":"invalid-argument-value","analyzedSha":"fb308bd8c3f12c79f4ae89bef67fadf6c80d036e","analyzedAt":"2026-09-06T11:37:12.241Z","contentChangedAt":"2026-09-06T11:37:12.241Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}