{"record":{"id":"1f393b44e811723f","repo":"eclipse-vertx/vert.x","slug":"null-delegate-not-allowed","errorCode":null,"errorMessage":"Null delegate not allowed","messagePattern":"Null delegate not allowed","errorType":"validation","errorClass":"NullPointerException","httpStatus":null,"severity":"error","filePath":"vertx-core/src/main/java/io/vertx/core/internal/VertxWrapper.java","lineNumber":69,"sourceCode":"import java.util.concurrent.TimeUnit;\nimport java.util.function.Supplier;\n\n/**\n * A wrapper class that delegates all method calls to the {@link #delegate} instance.\n *\n * Implementing the {@link Vertx} interface is not encouraged however if that is necessary, implementations\n * should favor extending this class to ensure minimum breakage when new methods are added to the interace.\n *\n * The delegate instance can be accessed using protected final {@link #delegate} field, any method of the {@code Vertx}\n * interface can be overridden.\n */\npublic abstract class VertxWrapper implements VertxInternal {\n\n  protected final VertxInternal delegate;\n\n  protected VertxWrapper(VertxInternal delegate) {\n    if (delegate == null) {\n      throw new NullPointerException(\"Null delegate not allowed\");\n    }\n    this.delegate = delegate;\n  }\n\n  @Override\n  public <C> CloseableResource<C> registerResource(CloseableResource<C> resource) {\n    return delegate.registerResource(resource);\n  }\n\n  @Override\n  public <C extends io.vertx.core.internal.Closeable> CloseableResource<C> createSharedResource(String resourceKey, String resourceName, Supplier<C> factory) {\n    return delegate.createSharedResource(resourceKey, resourceName, factory);\n  }\n\n  @Override\n  public NetServer createNetServer(TcpServerConfig config, ServerSSLOptions sslOptions) {\n    return delegate.createNetServer(config, sslOptions);\n  }","sourceCodeStart":51,"sourceCodeEnd":87,"githubUrl":"https://github.com/eclipse-vertx/vert.x/blob/fb308bd8c3f12c79f4ae89bef67fadf6c80d036e/vertx-core/src/main/java/io/vertx/core/internal/VertxWrapper.java#L51-L87","documentation":"VertxWrapper is an abstract base for decorators around VertxInternal; its constructor rejects a null delegate immediately. Wrapping a null Vertx instance is a programming error, so it throws NullPointerException at construction time rather than failing later on first delegate use.","triggerScenarios":"Calling a subclass constructor such as new VertxImplWrapper(null) or passing a null result from a factory/lookup (e.g. an unset Vertx holder) into any VertxWrapper subclass.","commonSituations":"Dependency injection wiring where the Vertx bean was not created; static holder field never initialized; refactoring that removed the Vertx.builder().build() call.","solutions":["Pass a non-null VertxInternal, e.g. (VertxInternal) vertx or Vertx.builder().build()","Check the value for null before constructing the wrapper and fail with a clear message at the wiring site","Fix the DI/factory configuration so the Vertx instance is actually produced"],"exampleFix":"// before\nnew MyVertxWrapper(lookupVertx()); // may return null\n// after\nVertxInternal v = lookupVertx();\nObjects.requireNonNull(v, \"vertx instance missing\");\nnew MyVertxWrapper(v);","handlingStrategy":"validation","validationCode":"Objects.requireNonNull(vertxInternal, \"Vertx instance must not be null before wrapping\");","typeGuard":null,"tryCatchPattern":"try { new MyWrapper(v); } catch (NullPointerException e) { failFast(\"Vertx not initialized\"); }","preventionTips":["Initialize the Vertx instance once at startup and store it in a guaranteed-non-null holder","Use Objects.requireNonNull at wiring boundaries for early, clear failures","Check DI configuration so the Vertx bean is always provided"],"tags":["null-pointer","wrapper","vertx"],"backgroundTag":"null-argument","analyzedSha":"fb308bd8c3f12c79f4ae89bef67fadf6c80d036e","analyzedAt":"2026-09-06T11:37:12.241Z","contentChangedAt":"2026-09-06T11:37:12.241Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}