ApplicationUser from issue.getReporter

Looking for some help on an existing plugin we created. We query for issues and then pull the Reporter for each issue found from the query.
My issue is the Application User is always null and I cannot find the Reporter name. I found that we needed to use getResults for the query and not getIssues, but this still had not cleared my issue.
Please point me in the right direction.
I tried switching between issue.getReporter and issue.getReporterUser and getting the same results.
Brian
JIra Server 8.2.3
Atlassian SDK 8.0.16

private List<Issue> getSpamIssues(ApplicationUser user) throws SearchException {
        List<Issue> issues = new ArrayList<Issue>();
        JqlQueryBuilder jqlQueryBuilder = JqlQueryBuilder.newBuilder();
        Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.DATE, (int) (-1 * this.delay.longValue()));
        jqlQueryBuilder.where().resolution().eq(this.resolution).and()
                .resolutionDate().lt(calendar.getTime());
        Query query = jqlQueryBuilder.buildQuery();
        SearchResults searchResults = this.searchService.search(user, query,
                PagerFilter.getUnlimitedFilter());
        //issues = searchResults.getIssues();
        issues = searchResults.getResults();
        this.log.info("Searching: " + query.toString());

        for (Issue issue : issues) {
            ApplicationUser reporter = issue.getReporter();
            this.log.info("function reporter: " + reporter.getDisplayName()); **CRASHES HERE**
        }
        return issues;
    }

If reporter was null, reporter.getDisplayName() would be throwing a NullPointerException. Perhaps change your log line to this.log.info("function reporter: " + reporter.toString()) so that you can see the user object instead.

Additionally, you should provide us the log output, since right now you’re only giving us half the information you have.

Stephen,
Thank you for the reply.
getDisplayName should return a string, but I tried your reporter.ToString() method also and both deliver the same error messages:


2019-09-09 08:15:01,031 Caesium-1-3 ERROR anonymous Spam Cleanup Service [c.a.jira.service.ServiceRunner] An error occurred while trying to run service ‘Spam Cleanup Service’. null
java.lang.NullPointerException
at edu.syr.its.jira.services.SpamCleanupService.getSpamIssues(SpamCleanupService.java:326)
at edu.syr.its.jira.services.SpamCleanupService.run(SpamCleanupService.java:143)
at com.atlassian.jira.service.JiraServiceContainerImpl.run(JiraServiceContainerImpl.java:68)
at com.atlassian.jira.service.ServiceRunner.runService(ServiceRunner.java:62)
at com.atlassian.jira.service.ServiceRunner.runServiceId(ServiceRunner.java:44)
at com.atlassian.jira.service.ServiceRunner.runJob(ServiceRunner.java:32)
at com.atlassian.scheduler.core.JobLauncher.runJob(JobLauncher.java:134)
at com.atlassian.scheduler.core.JobLauncher.launchAndBuildResponse(JobLauncher.java:106)
at com.atlassian.scheduler.core.JobLauncher.launch(JobLauncher.java:90)
at com.atlassian.scheduler.caesium.impl.CaesiumSchedulerService.launchJob(CaesiumSchedulerService.java:435)
at com.atlassian.scheduler.caesium.impl.CaesiumSchedulerService.executeClusteredJob(CaesiumSchedulerService.java:430)
at com.atlassian.scheduler.caesium.impl.CaesiumSchedulerService.executeClusteredJobWithRecoveryGuard(CaesiumSchedulerService.java:454)
at com.atlassian.scheduler.caesium.impl.CaesiumSchedulerService.executeQueuedJob(CaesiumSchedulerService.java:382)
at com.atlassian.scheduler.caesium.impl.SchedulerQueueWorker.executeJob(SchedulerQueueWorker.java:66)
at com.atlassian.scheduler.caesium.impl.SchedulerQueueWorker.executeNextJob(SchedulerQueueWorker.java:60)
at com.atlassian.scheduler.caesium.impl.SchedulerQueueWorker.run(SchedulerQueueWorker.java:35)
at java.lang.Thread.run(Thread.java:748)


I apologize for not giving this earlier (Standard procedure). But let me know what you think.
Brian

Which line does this reference? Line 326?

that the:
this.log.info("function reporter: " + reporter.toString());

Can you show us a sanitized screenshot proving the Issue Reporter is not null? Perhaps the value actually is null?

Stephen,
Ok, I got it. I’m not posted nulls anymore and I can see everything in my log files. Here is what I have:

for (Issue issue : issues) {
    this.log.info("Issue: " + issue.getKey());
    this.log.info("ReporterID: " + issue.getReporterId());

    try {
        ApplicationUser reporter = issue.getReporter();
        this.log.info("got AppUser");

        if (reporter == null) {
            this.log.info("user is null");
        }
        else {
            PropertySet reporterProps = this.userPropertyManager.getPropertySet(reporter);
            this.log.info("got Reporter Property");
            this.log.info("reporter is: " + reporter.getName().toString());
        }

    } catch (Exception ex) {
        this.log.info("error within Issue");
        this.log.info(ex.getMessage(), ex);
    }
}

And my log:
2019-09-10 14:00:39,792 Caesium-1-3 INFO anonymous Spam Cleanup Service [e.s.i.jira.services.SpamCleanupService] Issue: AASCSYS-2607
2019-09-10 14:00:39,793 Caesium-1-3 INFO anonymous Spam Cleanup Service [e.s.i.jira.services.SpamCleanupService] ReporterID: mail@188gametransfer.net
2019-09-10 14:00:39,794 Caesium-1-3 INFO anonymous Spam Cleanup Service [e.s.i.jira.services.SpamCleanupService] got Reporter Property
2019-09-10 14:00:39,794 Caesium-1-3 INFO anonymous Spam Cleanup Service [e.s.i.jira.services.SpamCleanupService] reporter is: mail@188gametransfer.net

I’m not 100% sure of why it is now functioning, must be with reporter.getname().toString(). The toString and ensuring it is a string is working great.
Thank you so much!

Happy to assist, good luck now! :slight_smile: