From 72dd22d49032672cad61509edc07a69b065a9d2c Mon Sep 17 00:00:00 2001 From: Nayan <83352306+nayan-rafiq@users.noreply.github.com> Date: Fri, 8 Oct 2021 19:27:16 +0600 Subject: [PATCH] fix: added a check to address NPE in home page when user has no organization (#8259) --- .../server/solutions/ApplicationFetcher.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/solutions/ApplicationFetcher.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/solutions/ApplicationFetcher.java index f36621a00420..155b28cec3e7 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/solutions/ApplicationFetcher.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/solutions/ApplicationFetcher.java @@ -70,11 +70,18 @@ public Mono getAllApplications() { User user = userAndUserDataTuple.getT1(); UserData userData = userAndUserDataTuple.getT2(); + UserHomepageDTO userHomepageDTO = new UserHomepageDTO(); + userHomepageDTO.setUser(user); + Set orgIds = user.getOrganizationIds(); + if(CollectionUtils.isEmpty(orgIds)) { + userHomepageDTO.setOrganizationApplications(new ArrayList<>()); + return Mono.just(userHomepageDTO); + } // create a set of org id where recently used ones will be at the beginning List recentlyUsedOrgIds = userData.getRecentlyUsedOrgIds(); - Set orgIdSortedSet = new LinkedHashSet<>(orgIds.size()); + Set orgIdSortedSet = new LinkedHashSet<>(); if(recentlyUsedOrgIds != null && recentlyUsedOrgIds.size() > 0) { // user has a recently used list, add them to the beginning orgIdSortedSet.addAll(recentlyUsedOrgIds); @@ -86,9 +93,6 @@ public Mono getAllApplications() { .findByMultipleOrganizationIds(orgIds, READ_APPLICATIONS) .collectMultimap(Application::getOrganizationId, Function.identity()); - UserHomepageDTO userHomepageDTO = new UserHomepageDTO(); - userHomepageDTO.setUser(user); - return organizationService .findByIdsIn(orgIds, READ_ORGANIZATIONS) .collectMap(Organization::getId, v -> v)