This is not safe as the returned collection may be immutable. It should be Set<Annotation> annotations = new HashSet<>(at.getAnnotations())