Skip to content

NPE in Organization(s)Resource when using Quarkus Rest Client #34335

@ebondu

Description

@ebondu

Before reporting an issue

  • I have read and understood the above terms for submitting issues, and I understand that my issue may be closed without action if I do not follow them.

Area

admin/api

Describe the bug

Hi,

Using the quarkus-rest-client builder from a custom provider leads to an NPE :
var service = QuarkusRestClientBuilder.newBuilder().baseUri(URI.create(url)).build(MyService.class);

The NPE is related to admin events in OrganizationResource and OrganizationsResources constructors and are easy to fix:

public OrganizationResource() {
   // needed for registering to the JAX-RS stack
   this(null, null, null);
}

public OrganizationResource(KeycloakSession session, OrganizationModel organization, AdminEventBuilder adminEvent) {
   this.session = session;
   this.provider = session == null ? null : session.getProvider(OrganizationProvider.class);
   this.organization = organization;
   // prevent NPE on adminEvent
   this.adminEvent = adminEvent == null ? null : adminEvent.resource(ResourceType.ORGANIZATION);
}

and

public OrganizationsResource() {
    // needed for registering to the JAX-RS stack
    this(null, null, null);
}

public OrganizationsResource(KeycloakSession session, AdminPermissionEvaluator auth, AdminEventBuilder adminEvent) {
   this.session = session;
   this.provider = session == null ? null : session.getProvider(OrganizationProvider.class);
   this.auth = auth;
   // prevent NPE on adminEvent
   this.adminEvent = adminEvent == null ? null : adminEvent.resource(ResourceType.ORGANIZATION);
}

Here are the dependencies declared in the custom provider (added in keycloak-quarkus-server / keycloak-quarkus-server-deployment):

<dependency>
   <groupId>io.quarkus</groupId>
   <artifactId>quarkus-rest-client</artifactId>
   <scope>provided</scope>
</dependency>
<dependency>
   <groupId>io.quarkus</groupId>
   <artifactId>quarkus-rest-client-jackson</artifactId>
   <scope>provided</scope>
</dependency>

Organization/Organizations classes are not used the provider and I don't know why the quarkus rest client instantiate this classes with the default constructor, so maybe there is a better solution to prevent the NPE.

Best regards.

Version

26

Regression

  • The issue is a regression

Expected behavior

No NPE when using quarkus-rest-client

Actual behavior

NPE when using the quarkus rest builder

How to Reproduce?

Add quarkus-rest-client / quarkus-rest-client-jackson dependencies in a keycloak distribution and try to instantiate a service client with QuarkusRestClientBuilder.

Anything else?

No response

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions