The Atlassian Community Forums are currently in read-only mode. We will be relaunching on a new platform on September 22 (read more here). We apologize for the extended downtime. For concerns or questions, please email communitymanagers@atlassian.com. See you on the other side, on the new Atlassian Community Forums! :)

×

Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Getting NullPointerException with findUserNames from UserSearchService

Azhak Anwar
November 28, 2024

Asking the question here as the developer community is not letting me post there. 

--

 

Good Day!

I'm following a tutorial to develop a Jira Plugin but am stuck at the REST API and getting a NullPointerException.
I am trying to search for users with the UserSearchService interface and its method findUserNames(), but I’m getting the exception.

Any help to avoid this exception and get the users is much appreciated! 

Following is my code snippet from the rest directory:

package io.codeclou.kitchen.duty.rest;
import io.codeclou.kitchen.duty.config.MyPluginJavaConfig;
...
@Named
@Path("/user")
public class UserSearchResource {
    public MyPluginJavaConfig myPluginJavaConfig;
    @Autowired
    public UserSearchResource(MyPluginJavaConfig myPluginJavaConfig) {
        this.myPluginJavaConfig = myPluginJavaConfig;
    }
    @GET
    @Path("/search")
    @Produces({MediaType.APPLICATION_JSON})
    public Response searchUsers(@QueryParam("query") final String userQuery,
                                @Context HttpServletRequest request) {
        List<UserSearchResourceModel> users = findUsers(userQuery);
        return Response.ok(users).build();
    }
    private List<UserSearchResourceModel> findUsers(String query) {
        List<UserSearchResourceModel> userSearchResourceModels = new ArrayList<>();
        UserSearchParams searchParams = UserSearchParams.builder()
            .includeActive(true)
            .sorted(true)
            .build();
        List<String> users = this.myPluginJavaConfig.userSearchService.findUserNames(query, searchParams);
        if (users != null) {
            for (String user : users) {
                userSearchResourceModels.add(new UserSearchResourceModel(user, user));
            }
        }
        return userSearchResourceModels;
    }
}

Config File: 

package io.codeclou.kitchen.duty.config;

import com.atlassian.jira.bc.user.search.UserSearchService;
import com.atlassian.plugin.spring.scanner.annotation.imports.ComponentImport;
...

@Configuration
@Import({
    ModuleFactoryBean.class,
    PluginAccessorBean.class
})

public class MyPluginJavaConfig {
    @Bean
    public ApplicationProperties applicationProperties() {
        return importOsgiService(ApplicationProperties.class);
    }

    @
Bean
    public MyPluginComponent myPluginComponent(ApplicationProperties applicationProperties) {
        return new MyPluginComponentImpl(applicationProperties);
    }

    @
Bean
   
public FactoryBean<ServiceRegistration> registerMyDelegatingService(
        final MyPluginComponent mypluginComponent) {
        return exportOsgiService(mypluginComponent, null, MyPluginComponent.class);
    }
    @ComponentImport
    public UserSearchService userSearchService;
}

Logs:

[INFO] [talledLocalContainer] Nov 28, 2024 4:02:08 PM com.sun.jersey.server.impl.application.WebApplicationImpl _initiate
[INFO] [talledLocalContainer] INFO: Initiating Jersey application, version 'Jersey: 1.19 02/11/2015 03:25 AM'
[INFO] [talledLocalContainer] Nov 28, 2024 4:02:08 PM com.sun.jersey.api.wadl.config.WadlGeneratorLoader loadWadlGenerator
[INFO] [talledLocalContainer] INFO: Loading wadlGenerator com.sun.jersey.server.wadl.generators.WadlGeneratorApplicationDoc
[INFO] [talledLocalContainer] Nov 28, 2024 4:02:08 PM com.sun.jersey.api.wadl.config.WadlGeneratorLoader loadWadlGenerator
[INFO] [talledLocalContainer] INFO: Loading wadlGenerator com.atlassian.plugins.rest.doclet.generators.grammars.WadlGrammarsAdaptor
[INFO] [talledLocalContainer] Nov 28, 2024 4:02:08 PM com.sun.jersey.api.wadl.config.WadlGeneratorLoader loadWadlGenerator
[INFO] [talledLocalContainer] INFO: Loading wadlGenerator com.atlassian.plugins.rest.doclet.generators.resourcedoc.AtlassianWadlGeneratorResourceDocSupport
[INFO] [talledLocalContainer] 2024-11-28 16:02:11,644 http-nio-2990-exec-2 ERROR admin 962x12382x1 11mu90j 0:0:0:0:0:0:0:1 /rest/kitchenduty/1.0/user/search [c.a.p.r.c.error.jersey.ThrowableExceptionMapper] Uncaught exception thrown by REST service: null
[INFO] [talledLocalContainer] java.lang.NullPointerException
[INFO] [talledLocalContainer]   at io.codeclou.kitchen.duty.rest.UserSearchResource.findUsers(UserSearchResource.java:68)
[INFO] [talledLocalContainer]   at io.codeclou.kitchen.duty.rest.UserSearchResource.searchUsers(UserSearchResource.java:58)

 

1 answer

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
vikram
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Champions.
December 1, 2024

Hi @Azhak Anwar 

I suspect some null user might be there, please check the users table from database. (let me know if it helped) 

try to check the below knowledge base url, might be helpful.

https://confluence.atlassian.com/jirakb/nullpointerexception-when-trying-to-access-the-user-browser-204053369.html

with Regards

Vikram P 

DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
FREE
TAGS
AUG Leaders

Atlassian Community Events