Skip to content

Commit

Permalink
A ConcurrentHashMap does not work with null keys or values. This mean…
Browse files Browse the repository at this point in the history
…s it will crash when you call ConcurrentHashMap.getOrDefault(null).

We were calling ConcurrentHashMap.getOrDefault(userId), and userId was nullable in that context.

Fixed logic to prevent ConcurrentHashMap.getOrDefault method being called with null input.
  • Loading branch information
krishna-patel-ch committed Sep 9, 2024
1 parent 197a1f6 commit 29d368c
Showing 1 changed file with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ public AssociationsList daoToDto( final Page<AssociationDao> associationsList, f
final var endpointUrl = computeEndpointUrl( companyDetails );
final var users = Objects.isNull( userDetails ) ? usersService.fetchUserDetails( associationsList.stream() ) : Map.of( userDetails.getUserId(), userDetails );
final var companies = Objects.isNull( companyDetails ) ? companyService.fetchCompanyProfiles( associationsList.stream() ) : Map.of( companyDetails.getCompanyNumber(), companyDetails );
final var associations = associationsList.map( associationDao -> daoToDto( associationDao, users.getOrDefault( associationDao.getUserId(), null ), companies.get( associationDao.getCompanyNumber() ) ) );
final var associations = associationsList.map( associationDao -> {
final var user = Objects.isNull( associationDao.getUserId() ) ? null : users.getOrDefault( associationDao.getUserId(), null );
final var company = companies.get( associationDao.getCompanyNumber() );
return daoToDto( associationDao, user, company );
} );
return enrichWithMetadata( associations, endpointUrl );
}

Expand Down

0 comments on commit 29d368c

Please sign in to comment.