Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Security level memory leak #2013

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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<Class<? extends Annotation>, List<Annotation>> m = new HashMap<>();
builder.classAnnotations.forEach((key, value) -> m.put(key, Collections.unmodifiableList(value)));
this.classLevelAnnotations = Collections.unmodifiableMap(m);

Map<Class<? extends Annotation>, List<Annotation>> meth = new HashMap<>();
builder.methodAnnotations.forEach((key, value) -> meth.put(key, Collections.unmodifiableList(value)));
this.methodLevelAnnotations = Collections.unmodifiableMap(meth);
}

/**
Expand Down Expand Up @@ -112,11 +118,12 @@ public <T extends Annotation> List<T> combineAnnotations(Class<T> annotationType
public Map<Class<? extends Annotation>, List<Annotation>> allAnnotations() {
Map<Class<? extends Annotation>, List<Annotation>> result = new HashMap<>(classLevelAnnotations);
methodLevelAnnotations.forEach((key, value) -> {
List<Annotation> 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;
}
Expand Down