quarkusio/quarkus · error · IllegalStateException

Links context has not been initialized

Error message

Links context has not been initialized

What it means

RestLinksProviderImpl manages the REST links metadata produced by the quarkus-rest-links extension at build time. verifyInit() throws this IllegalStateException when getTypeLinks()/getInstanceLinks() are invoked before the deployment-time initialization step has populated the links container. In a properly built Quarkus application this never happens; it indicates the provider is being used outside an initialized REST links context.

Source

Thrown at extensions/resteasy-reactive/rest-links/runtime/src/main/java/io/quarkus/resteasy/reactive/links/runtime/RestLinksProviderImpl.java:87

        return builder;
    }

    private Object[] getPathParameterValues(LinkInfo linkInfo, Object instance) {
        List<Object> values = new ArrayList<>(linkInfo.getPathParameters().size());
        for (String name : linkInfo.getPathParameters()) {
            GetterAccessor accessor = getterAccessorsContainer.get(linkInfo.getEntityType(), name);
            if (accessor != null) {
                values.add(accessor.get(instance));
            } else {
                values.add("{" + name + "}");
            }
        }
        return values.toArray();
    }

    private void verifyInit() {
        if (linksContainer == null) {
            throw new IllegalStateException("Links context has not been initialized");
        }
        if (getterAccessorsContainer == null) {
            throw new IllegalStateException("Getter accessors container has not been initialized");
        }
    }
}

View on GitHub (pinned to e1c734241f)

Solutions

  1. Ensure the application depends on quarkus-rest-links (runtime + deployment) so the build-time recorder initializes the links context
  2. Only call getTypeLinks/getInstanceLinks after Quarkus startup (e.g. from a request handler or @Observes StartupEvent), not from static init
  3. For tests, use @QuarkusTest so the full container boots and initializes the provider
  4. Guard usage: check that you are inside a booted Quarkus application before accessing the provider

Example fix

// before
RestLinks restLinks = RestLinksProvider.get().getTypeLinks(MyDto.class);
// after (only after startup)
void onStart(@Observes StartupEvent ev) {
    RestLinks restLinks = RestLinksProvider.get().getTypeLinks(MyDto.class);
}
Defensive patterns

Strategy: validation

Validate before calling

RestLinksProvider provider = RestLinksProvider.get();
// rely on @QuarkusTest bootstrapping; defensively:
if (!isQuarkusBooted()) throw new SkipException("Rest links not initialized");

Type guard

boolean linksReady(RestLinksProvider p) {
    try { p.getTypeLinks(Object.class); return true; }
    catch (IllegalStateException e) { return false; }
}

Try / catch

try {
    links = RestLinksProvider.get().getTypeLinks(type);
} catch (IllegalStateException e) {
    LOG.warn("REST links context unavailable", e);
    links = List.of();
}

Prevention

When it happens

Trigger: Calling RestLinksProvider.get() then getTypeLinks(...) or getInstanceLinks(...) when the RestLinksRecorder never ran or did not inject the links container (e.g. non-Quarkus test, wrong classloader, extension not present).

Common situations: Unit-testing code that depends on RestLinksProvider without bootstrapping Quarkus; using the provider in a plain Java SE context; the rest-links deployment module missing from the application so the recorder never initializes the containers.

Related errors


AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05). Data as JSON: /api/errors/b10fac59b14f65ab. Report an issue: GitHub.