diff --git a/src/checkers/inference/VariableAnnotator.java b/src/checkers/inference/VariableAnnotator.java index 91becc7c..63831199 100644 --- a/src/checkers/inference/VariableAnnotator.java +++ b/src/checkers/inference/VariableAnnotator.java @@ -453,7 +453,7 @@ private void addExistentialVariable(final AnnotatedTypeVariable typeVar, final T // TODO: THIS CRASHES ON RECURSIVE TYPES typeVarDecl = inferenceTypeFactory.getAnnotatedType(typeVarDeclElem); } else { - typeVarDecl = elementToAtm.get(typeVarDeclElem); + typeVarDecl = elementToAtm.get(typeVarDeclElem).deepCopy(); // TODO: I THINK THIS IS UNNECESSARY DUE TO InferenceVisitor.visitVariable // if(tree instanceof VariableTree && !treeToVariable.containsKey(tree)) { // if it's a declaration of a variable, store it // final Element varElement = TreeUtils.elementFromDeclaration((VariableTree) tree); @@ -599,7 +599,8 @@ public ConstantSlot getTopConstant() { * @see checkers.inference.VariableAnnotator#annotateElementFromStore */ public void storeElementType(final Element element, final AnnotatedTypeMirror atm) { - elementToAtm.put(element, atm); + final AnnotatedTypeMirror copy = atm.deepCopy(); + elementToAtm.put(element, copy); } /** @@ -1204,10 +1205,6 @@ public Void visitTypeVariable(AnnotatedTypeVariable typeVar, Tree tree) { final TypeParameterElement typeParamElement = (TypeParameterElement) typeVar.getUnderlyingType().asElement(); final TypeParameterTree typeParameterTree = (TypeParameterTree) tree; - if (!elementToAtm.containsKey(typeParamElement)) { - storeElementType(typeParamElement, typeVar); - } - // add lower bound annotation addPrimaryVariable(typeVar.getLowerBound(), tree); @@ -1252,6 +1249,11 @@ public Void visitTypeVariable(AnnotatedTypeVariable typeVar, Tree tree) { upperBound.addAnnotation(slotManager.getAnnotation(extendsSlot)); } + if (!elementToAtm.containsKey(typeParamElement)) { + // cache the element ATM when it's fully annotated + storeElementType(typeParamElement, typeVar); + } + } else { addExistentialVariable(typeVar, tree, false);