{"action":"created","issue":{"url":"https://api.github.com/repos/spring-projects/spring-security/issues/5834","repository_url":"https://api.github.com/repos/spring-projects/spring-security","labels_url":"https://api.github.com/repos/spring-projects/spring-security/issues/5834/labels{/name}","comments_url":"https://api.github.com/repos/spring-projects/spring-security/issues/5834/comments","events_url":"https://api.github.com/repos/spring-projects/spring-security/issues/5834/events","html_url":"https://github.com/spring-projects/spring-security/issues/5834","id":359135556,"node_id":"MDU6SXNzdWUzNTkxMzU1NTY=","number":5834,"title":"SessionRegistryImpl should use computeIfAbsent","user":{"login":"jzheaux","id":3627351,"node_id":"MDQ6VXNlcjM2MjczNTE=","avatar_url":"https://avatars0.githubusercontent.com/u/3627351?v=4","gravatar_id":"","url":"https://api.github.com/users/jzheaux","html_url":"https://github.com/jzheaux","followers_url":"https://api.github.com/users/jzheaux/followers","following_url":"https://api.github.com/users/jzheaux/following{/other_user}","gists_url":"https://api.github.com/users/jzheaux/gists{/gist_id}","starred_url":"https://api.github.com/users/jzheaux/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jzheaux/subscriptions","organizations_url":"https://api.github.com/users/jzheaux/orgs","repos_url":"https://api.github.com/users/jzheaux/repos","events_url":"https://api.github.com/users/jzheaux/events{/privacy}","received_events_url":"https://api.github.com/users/jzheaux/received_events","type":"User","site_admin":false},"labels":[{"id":322225082,"node_id":"MDU6TGFiZWwzMjIyMjUwODI=","url":"https://api.github.com/repos/spring-projects/spring-security/labels/Improvement","name":"Improvement","color":"eeeeee","default":false},{"id":322225078,"node_id":"MDU6TGFiZWwzMjIyMjUwNzg=","url":"https://api.github.com/repos/spring-projects/spring-security/labels/Web","name":"Web","color":"000000","default":false},{"id":993117074,"node_id":"MDU6TGFiZWw5OTMxMTcwNzQ=","url":"https://api.github.com/repos/spring-projects/spring-security/labels/first-timers-only","name":"first-timers-only","color":"7057ff","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":{"url":"https://api.github.com/repos/spring-projects/spring-security/milestones/82","html_url":"https://github.com/spring-projects/spring-security/milestone/82","labels_url":"https://api.github.com/repos/spring-projects/spring-security/milestones/82/labels","id":1567246,"node_id":"MDk6TWlsZXN0b25lMTU2NzI0Ng==","number":82,"title":"General Backlog","description":null,"creator":{"login":"spring-issuemaster","id":16028288,"node_id":"MDQ6VXNlcjE2MDI4Mjg4","avatar_url":"https://avatars2.githubusercontent.com/u/16028288?v=4","gravatar_id":"","url":"https://api.github.com/users/spring-issuemaster","html_url":"https://github.com/spring-issuemaster","followers_url":"https://api.github.com/users/spring-issuemaster/followers","following_url":"https://api.github.com/users/spring-issuemaster/following{/other_user}","gists_url":"https://api.github.com/users/spring-issuemaster/gists{/gist_id}","starred_url":"https://api.github.com/users/spring-issuemaster/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/spring-issuemaster/subscriptions","organizations_url":"https://api.github.com/users/spring-issuemaster/orgs","repos_url":"https://api.github.com/users/spring-issuemaster/repos","events_url":"https://api.github.com/users/spring-issuemaster/events{/privacy}","received_events_url":"https://api.github.com/users/spring-issuemaster/received_events","type":"User","site_admin":false},"open_issues":22,"closed_issues":2,"state":"open","created_at":"2016-02-05T21:45:56Z","updated_at":"2018-12-03T20:50:42Z","due_on":null,"closed_at":null},"comments":1,"created_at":"2018-09-11T16:58:41Z","updated_at":"2018-12-03T22:05:30Z","closed_at":null,"author_association":"CONTRIBUTOR","body":"Java 8 introduced `computeIfAbsent` on `ConcurrentHashMap`:\r\n\r\n> If the specified key is not already associated with a value,\r\n> attempts to compute its value using the given mapping function\r\n> and enters it into this map unless {@code null}.  The entire\r\n> method invocation is performed atomically, so the function is\r\n> applied at most once per key.\r\n\r\nSince `SessionRegistryImpl` uses `ConcurrentHashMap` and since it uses it as `<String, List<?>>`, it seems like an ideal circumstance to make the update to `principals` atomic.\r\n\r\nInstead of:\r\n\r\n```java\r\nSet<String> sessionsUsedByPrincipal = principals.get(principal);\r\n\r\nif (sessionsUsedByPrincipal == null) {\r\n\tsessionsUsedByPrincipal = new CopyOnWriteArraySet<>();\r\n\tSet<String> prevSessionsUsedByPrincipal = principals.putIfAbsent(principal,\r\n\t\t\tsessionsUsedByPrincipal);\r\n\tif (prevSessionsUsedByPrincipal != null) {\r\n\t\tsessionsUsedByPrincipal = prevSessionsUsedByPrincipal;\r\n\t}\r\n}\r\n\r\nsessionsUsedByPrincipal.add(sessionId);\r\n```\r\n\r\nIt could do:\r\n\r\n```java\r\nprincipals.computeIfAbsent(principal, key -> new CopyOnWriteArraySet<>())\r\n\t.add(sessionId);\r\n```"},"comment":{"url":"https://api.github.com/repos/spring-projects/spring-security/issues/comments/443888159","html_url":"https://github.com/spring-projects/spring-security/issues/5834#issuecomment-443888159","issue_url":"https://api.github.com/repos/spring-projects/spring-security/issues/5834","id":443888159,"node_id":"MDEyOklzc3VlQ29tbWVudDQ0Mzg4ODE1OQ==","user":{"login":"rwinch","id":362503,"node_id":"MDQ6VXNlcjM2MjUwMw==","avatar_url":"https://avatars0.githubusercontent.com/u/362503?v=4","gravatar_id":"","url":"https://api.github.com/users/rwinch","html_url":"https://github.com/rwinch","followers_url":"https://api.github.com/users/rwinch/followers","following_url":"https://api.github.com/users/rwinch/following{/other_user}","gists_url":"https://api.github.com/users/rwinch/gists{/gist_id}","starred_url":"https://api.github.com/users/rwinch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rwinch/subscriptions","organizations_url":"https://api.github.com/users/rwinch/orgs","repos_url":"https://api.github.com/users/rwinch/repos","events_url":"https://api.github.com/users/rwinch/events{/privacy}","received_events_url":"https://api.github.com/users/rwinch/received_events","type":"User","site_admin":false},"created_at":"2018-12-03T22:05:30Z","updated_at":"2018-12-03T22:05:30Z","author_association":"MEMBER","body":"@rmartinus Thanks the issue is yours! If you need any help, please let us know."}}
{"actor":{"display_login":"rwinch"}}