Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Index Checker annotations #1

Merged
merged 268 commits into from
May 23, 2018
Merged

Conversation

panacekcz
Copy link

@panacekcz panacekcz commented Feb 22, 2018

Adds Index Checker annotations.

Only the packages com.google.common.primitives and com.google.common.base are fully annotated, so to typecheck, run the Index Checker with -AonlyDefs=^com\.google\.common\.primitives\.|^com\.google\.common\.base\..

In order to get implicit annotations in class files, the Index Checker is run on all files, but index warnings are suppressed. To typecheck the packages that are annotated by index annotations, the Index checker is run in another phase only on these packages with warnings enabled.
See the properties in guava/pom.xml.

The used version of the Checker Framework is increased so that new annotations can be used.

@panacekcz
Copy link
Author

@kelloggm, I have addressed the comments.
@mernst, I have merged the master branch.

Copy link
Member

@mernst mernst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here are some small things that will improve the quality, and reduce the size, of the pull request.

guava/pom.xml Outdated
<annotatedJdk>${org.checkerframework:jdk8:jar}</annotatedJdk>
<checkerframework.extraargs></checkerframework.extraargs>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you document what these two variables (extraargs and extraargs2) are and how they should be used?
The same goes for index.only.arg.

@@ -17,6 +17,8 @@
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;

import org.checkerframework.checker.index.qual.NonNegative;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a matter of style, Google puts imports in alphabetical order, and with no blank lines (except a blank line separating import static from regular import). So this pull request should conform to that style, here and elsewhere.

checkNotNull(seq);

// length to truncate the sequence to, not including the truncation indicator
int truncationLength = maxLength - truncationIndicator.length();
@NonNegative int truncationLength = maxLength - truncationIndicator.length();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this local variable annotation needed?
Usually we only need one if there is a @Suppresswarnings or if the variable is re-assigned after being set, and neither seems to be true here.
(I don't have a particular objection to it, since it is useful documentation, but having smaller diffs and fewer annotations would be desirable.)
There are a number of other local variables that also have annotations but no @SuppressWarnings, so I wonder if they should also be removed.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is @SuppressWarnings on this method.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense, thanks.

public static int checkElementIndex(int index, int size) {
return checkElementIndex(index, size, "index");
public static @NonNegative int checkElementIndex(@NonNegative int index, @NonNegative int size) {
return checkElementIndex(index, size, "index"); // This comment contains @AnnotatedFor so that this line is ignored by count-suppressions
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove all comments like this, to keep the diffs small.

We use the count-suppressions script only to estimate which bugs/features to add to the Index Checker, but not for any statistics in a paper. (Or, that should be true if it is not currently!)
I could try to improve the regex in count-suppressions if this is too big an annoyance during development.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is used by the script print-fps.sh in the reproduction package.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although the to comment improves the numbers slightly, I don't think this should be merged into master because it would pollute the source code.

How about changing count-suppressions.sh to filter out lines that end with ;? Can you try that and see if it changes the numbers? If not, we could remove these comments and make that change to count-suppressions.sh instead. (If necessary, leave this pull request open for the ISSTA reviewers, and make a new one that eliminates the extraneous comments.)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done: typetools/checker-framework#1989. The usage of count-suppressions seems to allow these comments to be remvoed here.

@@ -34,6 +34,8 @@
import java.util.List;
import org.checkerframework.checker.nullness.compatqual.NullableDecl;

import org.checkerframework.checker.index.qual.NonNegative;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should go before the nullness import, in alphabetical order.

mernst and others added 13 commits May 15, 2018 22:39
Conflicts:
	guava/src/com/google/common/base/CaseFormat.java
	guava/src/com/google/common/base/Function.java
	guava/src/com/google/common/base/Functions.java
	guava/src/com/google/common/base/Joiner.java
	guava/src/com/google/common/base/Objects.java
	guava/src/com/google/common/base/Platform.java
	guava/src/com/google/common/base/Preconditions.java
	guava/src/com/google/common/base/Predicate.java
	guava/src/com/google/common/base/Predicates.java
	guava/src/com/google/common/base/Strings.java
	guava/src/com/google/common/base/Suppliers.java
	guava/src/com/google/common/base/Throwables.java
	guava/src/com/google/common/base/internal/Finalizer.java
	guava/src/com/google/common/collect/AbstractBiMap.java
	guava/src/com/google/common/collect/AbstractIterator.java
	guava/src/com/google/common/collect/AbstractListMultimap.java
	guava/src/com/google/common/collect/AbstractMapBasedMultiset.java
	guava/src/com/google/common/collect/AbstractMapEntry.java
	guava/src/com/google/common/collect/AbstractMultimap.java
	guava/src/com/google/common/collect/AbstractMultiset.java
	guava/src/com/google/common/collect/AbstractSetMultimap.java
	guava/src/com/google/common/collect/AbstractSortedSetMultimap.java
	guava/src/com/google/common/collect/ArrayListMultimap.java
	guava/src/com/google/common/collect/BiMap.java
	guava/src/com/google/common/collect/ByFunctionOrdering.java
	guava/src/com/google/common/collect/ClassToInstanceMap.java
	guava/src/com/google/common/collect/Collections2.java
	guava/src/com/google/common/collect/ComparatorOrdering.java
	guava/src/com/google/common/collect/CompoundOrdering.java
	guava/src/com/google/common/collect/ComputationException.java
	guava/src/com/google/common/collect/ConcurrentHashMultiset.java
	guava/src/com/google/common/collect/EnumBiMap.java
	guava/src/com/google/common/collect/EnumHashBiMap.java
	guava/src/com/google/common/collect/EnumMultiset.java
	guava/src/com/google/common/collect/ExplicitOrdering.java
	guava/src/com/google/common/collect/ForwardingCollection.java
	guava/src/com/google/common/collect/ForwardingConcurrentMap.java
	guava/src/com/google/common/collect/ForwardingList.java
	guava/src/com/google/common/collect/ForwardingMap.java
	guava/src/com/google/common/collect/ForwardingMapEntry.java
	guava/src/com/google/common/collect/ForwardingMultimap.java
	guava/src/com/google/common/collect/ForwardingMultiset.java
	guava/src/com/google/common/collect/ForwardingSet.java
	guava/src/com/google/common/collect/ForwardingSortedMap.java
	guava/src/com/google/common/collect/ForwardingSortedSet.java
	guava/src/com/google/common/collect/HashBiMap.java
	guava/src/com/google/common/collect/HashMultimap.java
	guava/src/com/google/common/collect/HashMultiset.java
	guava/src/com/google/common/collect/Hashing.java
	guava/src/com/google/common/collect/ImmutableClassToInstanceMap.java
	guava/src/com/google/common/collect/ImmutableCollection.java
	guava/src/com/google/common/collect/ImmutableEntry.java
	guava/src/com/google/common/collect/ImmutableEnumSet.java
	guava/src/com/google/common/collect/ImmutableList.java
	guava/src/com/google/common/collect/ImmutableListMultimap.java
	guava/src/com/google/common/collect/ImmutableMap.java
	guava/src/com/google/common/collect/ImmutableMultimap.java
	guava/src/com/google/common/collect/ImmutableMultiset.java
	guava/src/com/google/common/collect/ImmutableSet.java
	guava/src/com/google/common/collect/ImmutableSetMultimap.java
	guava/src/com/google/common/collect/ImmutableSortedMap.java
	guava/src/com/google/common/collect/ImmutableSortedSet.java
	guava/src/com/google/common/collect/Iterables.java
	guava/src/com/google/common/collect/Iterators.java
	guava/src/com/google/common/collect/LinkedHashMultimap.java
	guava/src/com/google/common/collect/LinkedHashMultiset.java
	guava/src/com/google/common/collect/LinkedListMultimap.java
	guava/src/com/google/common/collect/ListMultimap.java
	guava/src/com/google/common/collect/Lists.java
	guava/src/com/google/common/collect/MapDifference.java
	guava/src/com/google/common/collect/Maps.java
	guava/src/com/google/common/collect/Multimap.java
	guava/src/com/google/common/collect/Multimaps.java
	guava/src/com/google/common/collect/Multiset.java
	guava/src/com/google/common/collect/Multisets.java
	guava/src/com/google/common/collect/MutableClassToInstanceMap.java
	guava/src/com/google/common/collect/NullsFirstOrdering.java
	guava/src/com/google/common/collect/NullsLastOrdering.java
	guava/src/com/google/common/collect/ObjectArrays.java
	guava/src/com/google/common/collect/Ordering.java
	guava/src/com/google/common/collect/RegularImmutableBiMap.java
	guava/src/com/google/common/collect/RegularImmutableList.java
	guava/src/com/google/common/collect/RegularImmutableMap.java
	guava/src/com/google/common/collect/RegularImmutableSet.java
	guava/src/com/google/common/collect/RegularImmutableSortedSet.java
	guava/src/com/google/common/collect/ReverseOrdering.java
	guava/src/com/google/common/collect/SetMultimap.java
	guava/src/com/google/common/collect/Sets.java
	guava/src/com/google/common/collect/SingletonImmutableSet.java
	guava/src/com/google/common/collect/SortedSetMultimap.java
	guava/src/com/google/common/collect/Synchronized.java
	guava/src/com/google/common/collect/TreeMultimap.java
	guava/src/com/google/common/collect/TreeMultiset.java
	guava/src/com/google/common/primitives/Booleans.java
	guava/src/com/google/common/primitives/Bytes.java
	guava/src/com/google/common/primitives/Chars.java
	guava/src/com/google/common/primitives/Doubles.java
	guava/src/com/google/common/primitives/Floats.java
	guava/src/com/google/common/primitives/ImmutableDoubleArray.java
	guava/src/com/google/common/primitives/ImmutableIntArray.java
	guava/src/com/google/common/primitives/ImmutableLongArray.java
	guava/src/com/google/common/primitives/Ints.java
	guava/src/com/google/common/primitives/Longs.java
	guava/src/com/google/common/primitives/Shorts.java
	guava/src/com/google/common/primitives/UnsignedInteger.java
	guava/src/com/google/common/primitives/UnsignedLong.java
Putting the variable at the end caused no errors to be reported.
@panacekcz
Copy link
Author

@mernst, I have adressed the comments

@mernst
Copy link
Member

mernst commented May 22, 2018

Thanks. This looks good to me now -- I think it can be merged.

@mernst mernst merged commit 76189c3 into typetools:master May 23, 2018
@mernst
Copy link
Member

mernst commented May 24, 2018

Don't delete the branch yet -- leave it for the ISSTA AEC.

smillst pushed a commit to smillst/guava that referenced this pull request May 29, 2018
The old implementation had two bugs:
1. Tasks that threw RejectedExecutionException on submission would still execute later
2. Two threads submitting to an idle SequentialExecutor might see one submission succeed, even if the delegate threw REE. The submitted task wouldn't run until someone else successfully submitted another task.

This costs a possible extra lock acquisition  (to solve typetools#2) and an allocation (to solve typetools#1) when submitting to a SequentialExecutor that doesn't already have worker scheduled or running.

RELNOTES=n/a

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=181810127
kelloggm pushed a commit that referenced this pull request Jul 17, 2018
smillst pushed a commit that referenced this pull request Aug 23, 2019
To work with local Checker Framework installation.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants