Make the set of augmentations unmodifiable
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
-import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.ServiceLoader;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
+import static java.util.Collections.unmodifiableSet;
import static net.bytebuddy.matcher.ElementMatchers.anyOf;
import static net.bytebuddy.matcher.ElementMatchers.named;
private final Set<Augmentation<?>> augmentations;
public Augmenter() {
- augmentations = new HashSet<>();
+ Set<Augmentation<?>> augmentations = new HashSet<>();
Stream.of(
new AddApplicationCache(),
new AddLocationContext(),
@@ -75,6 +75,8 @@ public Augmenter() {
StreamSupport.stream(ServiceLoader.load(AugmenterProvider.class).spliterator(), false)
.forEach(provider -> augmentations.add(createAugmentation(provider)));
+
+ this.augmentations = unmodifiableSet(augmentations);
}
private static <X> Augmentation<X> createAugmentation(AugmenterProvider<X> provider) {
@@ -92,7 +94,7 @@ private Augmenter(Set<Augmentation<?>> augmentations, Augmentation<?> toAdd) {
toUse.addAll(augmentations);
toUse.add(toAdd);
- this.augmentations = Collections.unmodifiableSet(toUse);
+ this.augmentations = unmodifiableSet(toUse);
}
public <X> Augmenter addDriverAugmentation(AugmenterProvider<X> provider) {
