@SuppressWarnings("unchecked") private Map<Annotation, Annotation> removeAnnotationsThatPointToInvalidSpanNodes() { Map<Annotation, Annotation> removedAnnotations = new IdentityHashMap<Annotation, Annotation>(); Iterator<Annotation> annotationIt = iterator(); while (annotationIt.hasNext()) { Annotation a = annotationIt.next(); if (a.hasSpanNode() && !a.isSpanNodeValid()) { a.setSpanNode(null); a.setFieldValue(null); removedAnnotations.put(a, a); annotationIt.remove(); } } return removedAnnotations; }