From d12926bbc2380afcca192585f0e9ec53a2f04b93 Mon Sep 17 00:00:00 2001 From: David Kral Date: Wed, 17 Jun 2020 13:48:11 +0200 Subject: [PATCH] Security level memory leak Signed-off-by: David Kral --- .../io/helidon/security/SecurityLevel.java | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/security/security/src/main/java/io/helidon/security/SecurityLevel.java b/security/security/src/main/java/io/helidon/security/SecurityLevel.java index 43727084e1e..5f1b781cc25 100644 --- a/security/security/src/main/java/io/helidon/security/SecurityLevel.java +++ b/security/security/src/main/java/io/helidon/security/SecurityLevel.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2019, 2020 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -64,8 +64,14 @@ public static SecurityLevelBuilder create(SecurityLevel copyFrom) { private SecurityLevel(SecurityLevelBuilder builder) { this.className = builder.className; this.methodName = builder.methodName; - this.classLevelAnnotations = Collections.unmodifiableMap(builder.classAnnotations); - this.methodLevelAnnotations = Collections.unmodifiableMap(builder.methodAnnotations); + + Map, List> m = new HashMap<>(); + builder.classAnnotations.forEach((key, value) -> m.put(key, Collections.unmodifiableList(value))); + this.classLevelAnnotations = Collections.unmodifiableMap(m); + + Map, List> meth = new HashMap<>(); + builder.methodAnnotations.forEach((key, value) -> meth.put(key, Collections.unmodifiableList(value))); + this.methodLevelAnnotations = Collections.unmodifiableMap(meth); } /** @@ -112,11 +118,12 @@ public List combineAnnotations(Class annotationType public Map, List> allAnnotations() { Map, List> result = new HashMap<>(classLevelAnnotations); methodLevelAnnotations.forEach((key, value) -> { + List anno = new LinkedList<>(); if (result.containsKey(key)) { - result.get(key).addAll(value); - } else { - result.put(key, value); + anno.addAll(result.get(key)); } + anno.addAll(value); + result.put(key, anno); }); return result; }