From 5fd6110dec492f8ad2b4ff83dab9b4ce75eef7d5 Mon Sep 17 00:00:00 2001 From: d367wang Date: Wed, 13 Oct 2021 13:52:04 -0400 Subject: [PATCH 1/2] duplicate elementAtm cache before use (get/put) --- src/checkers/inference/VariableAnnotator.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/checkers/inference/VariableAnnotator.java b/src/checkers/inference/VariableAnnotator.java index 6e918ffd..42afce75 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); } /** From 5439890b56d15da227364bbb70b103ce49856060 Mon Sep 17 00:00:00 2001 From: d367wang Date: Sun, 1 May 2022 21:21:23 -0400 Subject: [PATCH 2/2] fix crash --- src/checkers/inference/VariableAnnotator.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/checkers/inference/VariableAnnotator.java b/src/checkers/inference/VariableAnnotator.java index 155cb76a..63831199 100644 --- a/src/checkers/inference/VariableAnnotator.java +++ b/src/checkers/inference/VariableAnnotator.java @@ -1205,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); @@ -1253,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);