Skip to content

Commit

Permalink
Change BugInCF to TypeSystemError in checker implementations
Browse files Browse the repository at this point in the history
  • Loading branch information
kelloggm committed Jul 20, 2021
1 parent ee41f69 commit 9161117
Show file tree
Hide file tree
Showing 26 changed files with 101 additions and 77 deletions.
Expand Up @@ -24,10 +24,10 @@
import org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedExecutableType;
import org.checkerframework.framework.util.AnnotatedTypes;
import org.checkerframework.javacutil.AnnotationUtils;
import org.checkerframework.javacutil.BugInCF;
import org.checkerframework.javacutil.ElementUtils;
import org.checkerframework.javacutil.TreeUtils;
import org.checkerframework.javacutil.TypesUtils;
import org.checkerframework.javacutil.UserError;
import org.plumelib.util.ArraysPlume;

/**
Expand Down Expand Up @@ -80,7 +80,7 @@ builderElement, getAutoValuePackageName() + ".AutoValue.Builder")) {
Element classContainingBuilderElement = builderElement.getEnclosingElement();
if (!ElementUtils.hasAnnotation(
classContainingBuilderElement, getAutoValuePackageName() + ".AutoValue")) {
throw new BugInCF(
throw new UserError(
"class "
+ classContainingBuilderElement.getSimpleName()
+ " is missing @AutoValue annotation");
Expand Down
Expand Up @@ -20,7 +20,7 @@
import org.checkerframework.framework.util.QualifierKindHierarchy;
import org.checkerframework.javacutil.AnnotationBuilder;
import org.checkerframework.javacutil.AnnotationUtils;
import org.checkerframework.javacutil.BugInCF;
import org.checkerframework.javacutil.TypeSystemError;
import org.checkerframework.javacutil.UserError;
import org.plumelib.reflection.Signatures;

Expand Down Expand Up @@ -149,7 +149,7 @@ protected AnnotationMirror leastUpperBoundWithElements(
} else if (qualifierKind2 == FENUM_KIND) {
return a2;
}
throw new BugInCF("Unexpected QualifierKinds %s %s", qualifierKind1, qualifierKind2);
throw new TypeSystemError("Unexpected QualifierKinds %s %s", qualifierKind1, qualifierKind2);
}

@Override
Expand All @@ -166,7 +166,7 @@ protected AnnotationMirror greatestLowerBoundWithElements(
} else if (qualifierKind2 == FENUM_KIND) {
return a1;
}
throw new BugInCF("Unexpected QualifierKinds %s %s", qualifierKind1, qualifierKind2);
throw new TypeSystemError("Unexpected QualifierKinds %s %s", qualifierKind1, qualifierKind2);
}
}
}
Expand Up @@ -25,7 +25,7 @@
import org.checkerframework.framework.util.QualifierKind;
import org.checkerframework.javacutil.AnnotationBuilder;
import org.checkerframework.javacutil.AnnotationUtils;
import org.checkerframework.javacutil.BugInCF;
import org.checkerframework.javacutil.TypeSystemError;
import scenelib.annotations.Annotation;
import scenelib.annotations.el.AField;
import scenelib.annotations.el.AMethod;
Expand Down Expand Up @@ -218,7 +218,7 @@ protected boolean isSubtypeWithElements(
} else if (subKind == INVALIDFORMAT_KIND && superKind == INVALIDFORMAT_KIND) {
return true;
}
throw new BugInCF("Unexpected kinds: %s %s", subKind, superKind);
throw new TypeSystemError("Unexpected kinds: %s %s", subKind, superKind);
}

@Override
Expand Down
Expand Up @@ -24,11 +24,11 @@
import org.checkerframework.common.wholeprograminference.WholeProgramInference;
import org.checkerframework.framework.type.AnnotatedTypeMirror;
import org.checkerframework.javacutil.AnnotationUtils;
import org.checkerframework.javacutil.BugInCF;
import org.checkerframework.javacutil.ElementUtils;
import org.checkerframework.javacutil.TreePathUtil;
import org.checkerframework.javacutil.TreeUtils;
import org.checkerframework.javacutil.TypesUtils;
import org.checkerframework.javacutil.UserError;

/**
* Whenever a format method invocation is found in the syntax tree, checks are performed as
Expand Down Expand Up @@ -208,7 +208,7 @@ private boolean forwardsArguments(
ExecutableElement calledMethodElement = TreeUtils.elementFromUse(invocationTree);
int callIndex = formatStringIndex(calledMethodElement);
if (callIndex == -1) {
throw new BugInCF(
throw new UserError(
"Method "
+ calledMethodElement
+ " is annotated @FormatMethod but has no String formal parameter");
Expand Down
Expand Up @@ -36,9 +36,9 @@
import org.checkerframework.framework.type.treeannotator.TreeAnnotator;
import org.checkerframework.framework.util.AnnotatedTypes;
import org.checkerframework.javacutil.AnnotationBuilder;
import org.checkerframework.javacutil.BugInCF;
import org.checkerframework.javacutil.ElementUtils;
import org.checkerframework.javacutil.TreeUtils;
import org.checkerframework.javacutil.TypeSystemError;
import org.checkerframework.javacutil.TypesUtils;

/** Annotated type factory for the GUI Effect Checker. */
Expand Down Expand Up @@ -307,7 +307,7 @@ public Effect getComputedEffectAtCallsite(
}
srcType = callerReceiver;
} else {
throw new BugInCF("Unexpected getMethodSelect() kind at callsite " + node);
throw new TypeSystemError("Unexpected getMethodSelect() kind at callsite " + node);
}

// Instantiate type-polymorphic effects
Expand Down
Expand Up @@ -32,7 +32,7 @@
import org.checkerframework.framework.util.QualifierKind;
import org.checkerframework.javacutil.AnnotationBuilder;
import org.checkerframework.javacutil.AnnotationUtils;
import org.checkerframework.javacutil.BugInCF;
import org.checkerframework.javacutil.TypeSystemError;
import org.plumelib.reflection.Signatures;

/**
Expand Down Expand Up @@ -257,7 +257,7 @@ protected boolean isSubtypeWithElements(
treeUtil.getI18nInvalidFormatValue(subAnno),
treeUtil.getI18nInvalidFormatValue(superAnno));
}
throw new BugInCF("Unexpected QualifierKinds: %s %s", subKind, superKind);
throw new TypeSystemError("Unexpected QualifierKinds: %s %s", subKind, superKind);
}

@Override
Expand Down
Expand Up @@ -10,7 +10,7 @@
import org.checkerframework.framework.flow.CFStore;
import org.checkerframework.framework.flow.CFValue;
import org.checkerframework.framework.type.QualifierHierarchy;
import org.checkerframework.javacutil.BugInCF;
import org.checkerframework.javacutil.TypeSystemError;

/**
* This struct contains all of the information that the refinement functions need. It's called by
Expand Down Expand Up @@ -65,7 +65,7 @@ public IndexRefinementInfo(
private static AnnotationMirror getAnno(Set<AnnotationMirror> set, QualifierHierarchy hierarchy) {
Set<? extends AnnotationMirror> tops = hierarchy.getTopAnnotations();
if (tops.size() != 1) {
throw new BugInCF(
throw new TypeSystemError(
"%s: Found %d tops, but expected one.%nFound: %s",
IndexRefinementInfo.class, tops.size(), tops);
}
Expand Down
Expand Up @@ -23,8 +23,8 @@
import org.checkerframework.framework.type.QualifierHierarchy;
import org.checkerframework.javacutil.AnnotationBuilder;
import org.checkerframework.javacutil.AnnotationUtils;
import org.checkerframework.javacutil.BugInCF;
import org.checkerframework.javacutil.TreeUtils;
import org.checkerframework.javacutil.TypeSystemError;

/**
* The Search Index Checker is used to help type the results of calls to the JDK's binary search
Expand Down Expand Up @@ -92,7 +92,7 @@ private List<String> getValueElement(AnnotationMirror am) {
} else if (areSameByClass(am, SearchIndexFor.class)) {
return AnnotationUtils.getElementValueArray(am, searchIndexForValueElement, String.class);
} else {
throw new BugInCF("indexForValue(%s)", am);
throw new TypeSystemError("indexForValue(%s)", am);
}
}

Expand Down
Expand Up @@ -20,8 +20,8 @@
import org.checkerframework.framework.type.AnnotatedTypeMirror;
import org.checkerframework.javacutil.AnnotationBuilder;
import org.checkerframework.javacutil.AnnotationUtils;
import org.checkerframework.javacutil.BugInCF;
import org.checkerframework.javacutil.Pair;
import org.checkerframework.javacutil.TypeSystemError;
import org.plumelib.util.CollectionsPlume;

/**
Expand Down Expand Up @@ -78,7 +78,7 @@ public static UBQualifier createUBQualifier(
// TODO: Ignores offset. Should we check that offset is not set?
return PolyQualifier.POLY;
default:
throw new BugInCF("createUBQualifier(%s, %s, ...)", am, offset);
throw new TypeSystemError("createUBQualifier(%s, %s, ...)", am, offset);
}
}

Expand Down Expand Up @@ -689,7 +689,7 @@ private AnnotationMirror convertToAnnotation(
builder.setValue("value", sequences);
builder.setValue("offset", offsets);
} else {
throw new BugInCF("What annoClass? " + annoClass);
throw new TypeSystemError("What annoClass? " + annoClass);
}
return builder.build();
}
Expand Down
Expand Up @@ -75,9 +75,9 @@
import org.checkerframework.framework.util.dependenttypes.DependentTypesHelper;
import org.checkerframework.javacutil.AnnotationBuilder;
import org.checkerframework.javacutil.AnnotationUtils;
import org.checkerframework.javacutil.BugInCF;
import org.checkerframework.javacutil.Pair;
import org.checkerframework.javacutil.TreeUtils;
import org.checkerframework.javacutil.TypeSystemError;

/**
* Implements the introduction rules for the Upper Bound Checker.
Expand Down Expand Up @@ -334,18 +334,32 @@ public boolean isRandomNextInt(Tree methodTree) {
return imf.isRandomNextInt(methodTree, processingEnv);
}

/**
* Creates a new @LTLengthOf annotation.
*
* @param names the arguments to @LTLengthOf
* @return a new @LTLengthOf annotation with the given arguments
*/
AnnotationMirror createLTLengthOfAnnotation(String... names) {
if (names == null || names.length == 0) {
throw new BugInCF("createLTLengthOfAnnotation: bad argument %s", Arrays.toString(names));
throw new TypeSystemError(
"createLTLengthOfAnnotation: bad argument %s", Arrays.toString(names));
}
AnnotationBuilder builder = new AnnotationBuilder(getProcessingEnv(), LTLengthOf.class);
builder.setValue("value", names);
return builder.build();
}

/**
* Creates a new @LTEqLengthOf annotation.
*
* @param names the arguments to @LTEqLengthOf
* @return a new @LTEqLengthOf annotation with the given arguments
*/
AnnotationMirror createLTEqLengthOfAnnotation(String... names) {
if (names == null || names.length == 0) {
throw new BugInCF("createLTEqLengthOfAnnotation: bad argument %s", Arrays.toString(names));
throw new TypeSystemError(
"createLTEqLengthOfAnnotation: bad argument %s", Arrays.toString(names));
}
AnnotationBuilder builder = new AnnotationBuilder(getProcessingEnv(), LTEqLengthOf.class);
builder.setValue("value", names);
Expand Down
Expand Up @@ -61,10 +61,10 @@
import org.checkerframework.framework.util.dependenttypes.DependentTypesHelper;
import org.checkerframework.javacutil.AnnotationBuilder;
import org.checkerframework.javacutil.AnnotationUtils;
import org.checkerframework.javacutil.BugInCF;
import org.checkerframework.javacutil.ElementUtils;
import org.checkerframework.javacutil.Pair;
import org.checkerframework.javacutil.TreeUtils;
import org.checkerframework.javacutil.TypeSystemError;
import org.plumelib.util.CollectionsPlume;

/**
Expand Down Expand Up @@ -359,7 +359,7 @@ protected AnnotationMirror leastUpperBoundWithElements(
} else if (qualifierKind2 == NEWOBJECT_KIND) {
return a1;
}
throw new BugInCF(
throw new TypeSystemError(
"leastUpperBoundWithElements(%s, %s, %s, %s, %s)",
a1, qualifierKind1, a2, qualifierKind2, lubKind);
}
Expand Down Expand Up @@ -396,7 +396,7 @@ protected AnnotationMirror greatestLowerBoundWithElements(
} else if (qualifierKind2 == GUARDEDBYUNKNOWN_KIND) {
return a1;
}
throw new BugInCF(
throw new TypeSystemError(
"greatestLowerBoundWithElements(%s, %s, %s, %s, %s)",
a1, qualifierKind1, a2, qualifierKind2, glbKind);
}
Expand Down
Expand Up @@ -57,10 +57,10 @@
import org.checkerframework.framework.util.StringToJavaExpression;
import org.checkerframework.framework.util.dependenttypes.DependentTypesError;
import org.checkerframework.javacutil.AnnotationUtils;
import org.checkerframework.javacutil.BugInCF;
import org.checkerframework.javacutil.ElementUtils;
import org.checkerframework.javacutil.TreePathUtil;
import org.checkerframework.javacutil.TreeUtils;
import org.checkerframework.javacutil.TypeSystemError;
import org.checkerframework.javacutil.TypesUtils;
import org.plumelib.util.CollectionsPlume;

Expand Down Expand Up @@ -1096,9 +1096,16 @@ private void checkLock(Tree tree, AnnotationMirror gbAnno) {
checkLockOfThisOrTree(tree, false, gbAnno);
}

/**
* Helper method tat checks the lock of either the implicit {@code this} or the given tree.
*
* @param tree a tree whose lock to check
* @param implicitThis true if checking the lock of the implicit {@code this}
* @param gbAnno a @GuardedBy annotation
*/
private void checkLockOfThisOrTree(Tree tree, boolean implicitThis, AnnotationMirror gbAnno) {
if (gbAnno == null) {
throw new BugInCF("LockVisitor.checkLock: gbAnno cannot be null");
throw new TypeSystemError("LockVisitor.checkLock: gbAnno cannot be null");
}
if (atypeFactory.areSameByClass(gbAnno, GuardedByUnknown.class)
|| atypeFactory.areSameByClass(gbAnno, GuardedByBottom.class)) {
Expand Down
Expand Up @@ -46,9 +46,9 @@
import org.checkerframework.framework.type.typeannotator.TypeAnnotator;
import org.checkerframework.javacutil.AnnotationBuilder;
import org.checkerframework.javacutil.AnnotationUtils;
import org.checkerframework.javacutil.BugInCF;
import org.checkerframework.javacutil.ElementUtils;
import org.checkerframework.javacutil.TreeUtils;
import org.checkerframework.javacutil.TypeSystemError;

/**
* The annotated type factory for the Must Call Checker. Primarily responsible for the subtyping
Expand Down Expand Up @@ -197,7 +197,7 @@ public void methodFromUsePreSubstitution(ExpressionTree tree, AnnotatedExecutabl
} else if (tree instanceof MemberReferenceTree) {
declaration = (ExecutableElement) TreeUtils.elementFromTree(tree);
} else {
throw new BugInCF("unexpected type of method tree: " + tree.getKind());
throw new TypeSystemError("unexpected type of method tree: " + tree.getKind());
}
changeNonOwningParameterTypesToTop(declaration, type);
super.methodFromUsePreSubstitution(tree, type);
Expand Down
Expand Up @@ -69,10 +69,10 @@
import org.checkerframework.framework.util.QualifierKind;
import org.checkerframework.javacutil.AnnotationBuilder;
import org.checkerframework.javacutil.AnnotationUtils;
import org.checkerframework.javacutil.BugInCF;
import org.checkerframework.javacutil.Pair;
import org.checkerframework.javacutil.TreePathUtil;
import org.checkerframework.javacutil.TreeUtils;
import org.checkerframework.javacutil.TypeSystemError;
import org.checkerframework.javacutil.TypesUtils;

/** The annotated type factory for the nullness type-system. */
Expand Down Expand Up @@ -638,7 +638,8 @@ protected boolean isSubtypeWithElements(
if (!subKind.isInSameHierarchyAs(NULLABLE) || !superKind.isInSameHierarchyAs(NULLABLE)) {
return this.isSubtypeInitialization(subAnno, subKind, superAnno, superKind);
}
throw new BugInCF("Unexpected annotations isSubtypeWithElements(%s, %s)", subAnno, superAnno);
throw new TypeSystemError(
"Unexpected annotations isSubtypeWithElements(%s, %s)", subAnno, superAnno);
}

@Override
Expand All @@ -652,7 +653,8 @@ protected AnnotationMirror leastUpperBoundWithElements(
|| !qualifierKind2.isInSameHierarchyAs(NULLABLE)) {
return this.leastUpperBoundInitialization(a1, qualifierKind1, a2, qualifierKind2);
}
throw new BugInCF("Unexpected annotations leastUpperBoundWithElements(%s, %s)", a1, a2);
throw new TypeSystemError(
"Unexpected annotations leastUpperBoundWithElements(%s, %s)", a1, a2);
}

@Override
Expand All @@ -666,7 +668,8 @@ protected AnnotationMirror greatestLowerBoundWithElements(
|| !qualifierKind2.isInSameHierarchyAs(NULLABLE)) {
return this.greatestLowerBoundInitialization(a1, qualifierKind1, a2, qualifierKind2);
}
throw new BugInCF("Unexpected annotations greatestLowerBoundWithElements(%s, %s)", a1, a2);
throw new TypeSystemError(
"Unexpected annotations greatestLowerBoundWithElements(%s, %s)", a1, a2);
}
}

Expand Down
Expand Up @@ -41,8 +41,8 @@
import org.checkerframework.framework.util.AnnotatedTypes;
import org.checkerframework.javacutil.AnnotationBuilder;
import org.checkerframework.javacutil.AnnotationUtils;
import org.checkerframework.javacutil.BugInCF;
import org.checkerframework.javacutil.TreeUtils;
import org.checkerframework.javacutil.TypeSystemError;
import org.checkerframework.javacutil.TypesUtils;

/**
Expand Down Expand Up @@ -401,7 +401,7 @@ private boolean hasNullableValueType(AnnotatedTypeMirror mapOrSubtype) {
AnnotatedTypes.asSuper(nullnessTypeFactory, mapOrSubtype, MAP_TYPE);
int numTypeArguments = mapType.getTypeArguments().size();
if (numTypeArguments != 2) {
throw new BugInCF("Wrong number %d of type arguments: %s", numTypeArguments, mapType);
throw new TypeSystemError("Wrong number %d of type arguments: %s", numTypeArguments, mapType);
}
AnnotatedTypeMirror valueType = mapType.getTypeArguments().get(1);
return valueType.hasAnnotation(NULLABLE);
Expand Down

0 comments on commit 9161117

Please sign in to comment.