Skip to content

Moe Sync - #1159

Merged
cushon merged 69 commits into
masterfrom
sync-master-2018/10/29
Nov 2, 2018
Merged

cushon merged 69 commits into
masterfrom
sync-master-2018/10/29

Conversation

@ronshapiro

Copy link
Copy Markdown
Contributor

This code has been reviewed and submitted internally. Feel free to discuss on the PR and we can submit follow-up changes as necessary.

Commits:

Remove unnecessary name check

This should already be guaranteed by the getSymbolsByName method

RELNOTES: n/a

7a46409


Miscellaneous cleanups RELNOTES: N/A

97c6e51


Fix a bug in the NoAllocationChecker that occurs when calling generic methods. The isAssignable check fails against generic parameters, so limit the varargs boxing check to only happen when the parameter is actually a varargs parameter, instead of just applying the assignability check all the time.

RELNOTES: Fix for how NoAllocationChecker handles generic methods.

77d7046


Nullness inference improvements to fix results for calls to non-generic methods: - don't propagate constraints from arguments to method results - derive inference results more like javac, to find results more often

Generic method calls where actual types have type parameters can now sometimes not have an inference result, but previously those results came from propagation from arguments to results, which can in general lead to wrong results

4ab41fb


Add a regression test for b/112275411

RELNOTES: N/A

1d92ce5


Interleave scanning for closed locks in LockNotBeforeTry

instead of scanning the try/finally and direct cases as two separate
passes. Also check for re-opening the same lock, and don't move the
first acquisition down to the second acquisition's release.

RELNOTES: N/A

a32b624


Add parameter names in comments to fix ArgumentSelectionDefectChecker warning

RELNOTES: N/A

411abde


Add a regression test for b/116048042 RELNOTES: N/A

86ce344


Suppress EqualsGetClass in Bindings.Key

RELNOTES: N/A

c0240d1


Avoid suggesting a fix for @annotations within {@code } tags: {@code @OverRide public void foo(); }

I can't find any way to escape an annotation within a {@code } tag. {@literal @} will be rendered exactly as written, as will @.

Perhaps the only answer is to use

 and manually escape any HTML entities within the code block so that {@literal @} can be used?

RELNOTES: N/A

2bca96f6422be4f1b9848cafb63adfa7f9027020


Add a pattern for Javadocs missing a summary line.

A summary line is required by the style guide on any public/protected Javadocs.

RELNOTES: Add Javadoc check for missing summary lines.

73002d79c78b4db45ceed26dbc1b46f6ec50d2e2


Update example version numbers

RELNOTES: N/A

00f1937eabb5b9f18939d9fca51a5a1bf4bd65c7


Change the DateFormatConstant bug checker to rename variable to lowerCamelCase when making a thread local suggestion.

ThreadLocal<java.text.DateFormat> is still mutable so constant casing seems wrong here.

RELNOTES:Change the DateFormatConstant bug checker to rename variable to lowerCamelCase when making a thread local suggestion.

02082476dd6091318102cfcc9dddfa35227896db


Change the semantics of the flags in ProtoFieldNullComparison.

RELNOTES: N/A

4bd8da92328918b9eb4f8b6aa020a729c43692c0


Make the type check in OverrideThrowableToString more robust.

Also simplify the fix generation, and don't emit a suggestion if the class overrides both (that doesn't seem erroneous to me).

RELNOTES: Fixes in OverrideThrowableToString.

a8ba6a97651c9b9a9f8e2647f2970d49f9a5a62a


Remove requireNonNull in LockNotBeforeTry.

RELNOTES: N/A

72ed919e0968cc9c3bb4bfb35016ec044967ac41


Fix NullPointerExceptions in Nullable Dereference. Fixes #1138.

Turns out that the crash was caused by static field imports -- they are JCFieldAccesses without a symbol.

RELNOTES: N/A

c15f7c546626709fd8945c219b097c909e7922f9


Add @contact and @team to KNOWN_OTHER_TAGS.

RELNOTES: N/A

554612a45816f280691e227e7aa74ef3c6f9ecb8


Implement ErrorProne checker to disallow usage of org.mockito.internal.*

Per mockito/mockito#80 (comment), we
(the Mockito core team where I am a member of) do not support any usages of
org.mockito.internal.* To that end, we are free to change/add/remove any
methods/classes/interfaces in these packages.

Therefore, I propose we write an ErrorProne check that prohibits the usage
of such classes, as well as gradually remove all of these imports. This
should then greatly ease the process of upgrading Mockito to 2.*

fed4399b344a474ee2749497af760d9592fb4622


Open-source a number of checks related to dealing with time-related bugs.

RELNOTES: Add a number of static analysis checks around appropriate
use of java.time and org.joda.time classes - APIs that are unclear,
don't do what most people expect, or are otherwise easy to trip on.

9f0513c081aa5cfaffe16e5a1e49a42364923592


Document the -XepOpt:MissingOverride:IgnoreInterfaceOverrides option

Fixes #1141

175069961b8dc9521f5b37f962dfa1b09968e9c9


Miscellaneous cleanups RELNOTES: N/A

4206bfe5150f72518fcfb8c3636e67b23c855353


Add assertThrows fix to MissingFail, using logic from TryFailRefactoring.

RELNOTES:N/A

30957a8fdea7bc398897ba35d0b214dd9bc74cc3


Add MEMBER_REFERENCE to switch of Kinds not requiring parens.

RELNOTES: N/A

ca4dc2cdeb81e0c07ebd0bbfa85d8016046a1337


Pull out common tags in InvalidTag, and add apiNote/implSpec/implNote as custom tags.

These seem not to be elevated to being canonical tags at this point, so this seems like the right home.

RELNOTES: Add java8 tags to InvalidTag.

6dfbd12acb19d575b9ed109a133fdd12b3b34224


Fix incorrect @throws documentation on Description.Builder classes.

RELNOTES: n/a

91041f662e2f7502258e611fed62d78062c393a2


Fix crash in TimeUnitConversionChecker when run directly on java.util.concurrent.TimeUnit

RELNOTES: n/a

2eb72f4d278c21752233d33a13e37913f2751843


Don't crash when @DoNotCall isn't on the classpath Fixes #1131 RELNOTES: N/A

9a3b2382e6f45737666b45f4ca4d6d075115d775


Fix a few issues with the MutableMethodReturnType checker where the checker would crash on certain methods.

See test file for added regression tests with examples.

RELNOTES: Fix a few issues with the MutableMethodReturnType checker where the checker would crash on certain methods.

6019e60957d32d893da7fe2bb3472315d42c8870


Fix typo to unblock documentation generation job.

3db44776a07d1ac0884d63eafcf9816c05825059


Update docs for @Matches to say that it should _only_ go on the @BeforeTemplate.

RELNOTES: update @Matches docs

aa8a4769649db741984ba035a08643733a722d2f


Add some sanity checks around source offsets in ParameterName check

Fixes #1135

RELNOTES: none

1a86e9919c488bb503515ed89b8f3762b73550f0


First attempt at a new treatise on why getClass() in equals() is wrong wrong wrong.

Fixes #1144

1b44e51150e170dfbe8fb32ccc3642a264439c73


Include the typeStr in the exception message thrown by VisitorState.getTypeFromString()

RELNOTES: Include the typeStr in the exception message thrown by VisitorState.getTypeFromString()

8e3e5a5eb0d67571c20ea6abc332fb3262f76b56


Fix false positives for JUnit's Theories runner. Treat @Theory and any other JUnit annotations as test annotations.

RELNOTES: N/A

31e4da3aecccdb377222f873c55a21591c5011a5


Add a pattern for unescaped entities in Javadocs, as well as generic type parameters.

We regex match for stuff that looks a bit like Type<A, B>. If it's inside a

/, we suggest wrapping that entire block with {@code } unless it has annotations in it (which then can't be escaped) or already escaped some HTML.

RELNOTES: Catch unescaped entities in Javadocs.

5e97091b81dc55bb30e9dd863e89fceaad7dca03


Add ASTHelpers.getFileName(CompilationUnitTree). All usages of getFileNameFromUri in Google use the URI directly from the CompilationUnitTree, and it's easier to find than needing to know a URI is accessible from the JavaFileObject.

RELNOTES: n/a

6f9448548796731ab1e3aa57fbda8bcc25c3658f


Add new bugchecker for static final fields with type mutability inconsistent with the name casing as per java-style

Finds and fixes constant case naming violations for static final variables when we're certain that the field type is mutable or immutable, respectively.

Fixes are suggested roughly using the following heuristic, which attempts to match the supposed most common intent, and only for private fields:

  • If the field type is determined to be immutable, and the casing is not UPPER_SNAKE_CASE, we rename it to be UPPER_SNAKE_CASE.
  • If the field type is determined to be mutable, and the casing is UPPER_SNAKE_CASE, we do the following:
    • If the field type is a collection, and not modified in the compiliation unit where it's defined, we try to make it immutable. If it is modified, we rename it.
    • If the field type is mutable proto2, we use the heuristic that it's not mutable if the field name is equal to IMMUTABLE_DEFAULT_INSTANCE (which is most likely frozen), and don't rename in that case. Otherwise we rename to lowerCamelCase.
    • In the remaining cases, we rename to lowerCamelCase.

RELNOTES: Add new bugchecker for static final fields with type mutability inconsistent with the name casing of Google's style guide

7cdb6303d331d38ce0a86a7ca95ce6567e6dc83f


Stop the Xplugin integration from infinitely recursing into compilesWithFix RELNOTES: N/A

28a8668d9a4a3a5527eb1f9d7e84537dc03e7050


Fix public test failures: * Update JavaTimeDefaultTimeZone's behavior to suggest adding ZoneId.systemDefault() * Update version of Mockito used so that MockitoInternalUsage works * Remove compiled protos from test sources as they don't work in maven at the moment

RELNOTES: n/a

24a125b3b05bbb40f3d1112670cf6ec23f6979e3


Add details about suppression to Unused's documentation.

RELNOTES: N/A

cd61727d63889d3aab6a7f7bc4313546ccf21679


Disallow null for BugChecker descriptions.

RELNOTES: Disallow null for BugChecker descriptions.

a68f010e0bb861e36758de584f5ce51d253bd208


Update the NoAllocationChecker to require the annotation be propagated to all overrides of a method that has the annotation.

RELNOTES: The NoAllocationChecker now requires the @NoAllocation annotation to be propagated to all overrides of a method that has the annotation, to reflect the contractual nature of the annotation.

663d7a329b6cf70685ee8034afdaa6ea7413c0f5


Add null check to IntLongMath to prevent NullPointerException.

RELNOTES: N/A

9d73c5eb914f705163de049cb44e63cac537a08c


Whitelist CompletableFuture#exceptionally in FutureReturnValueIgnored

Fixes #1154

RELNOTES: N/A

9ee12ef308c439743eaad76111af595f939d9ecc


Make CollectionToArraySafeParameter an error

RELNOTES: CollectionToArraySafeParameter is now an error

7ffc3423cff1e4e5dbc4d5546106da41d5027339


use nullness inference for all methods that return a generic type parameter

this allows using inference results for class-level type parameters, which helps in situations where those type parameters never appear in source code, e.g., in expressions like methodThatReturnsNonnullMap().get("key")

f77627caa67b9e0672e6415e8288ae4ec2ebef02


Fix a crash in LockNotBeforeTry

getReceiver rejects non-invocation ExpressionTrees

RELNOTES: N/A

e93490784ea9bcac7c3962c6322151a29feaa127


Make Unused more clever about which comments to delete.

RELNOTES: N/A

ec8a4b2af10443108a66e010b5a1630faea27114


Improve AutoValueFinalMethods check - Add more specific diagnostic instead of listing all 3 methods - Flag at first matched method instead of class - add sanity test for @Memoized abstract method

RELNOTES: Improve AutoValueFinalMethods check by adding more specific diagnostic at first matched method.

7797f703eac9eaf0fc899ec2686270c686fe67e0


Add test for Diagnostic String with multiple method matches for AutoValueFinalMethods check

RELNOTES: N/A

e05eaa56c99cb44e6c82162fd657c9d964cd4631


Avoid calling getAnnotation in VisibleForTestingMisused

and consolidate utilities for accessing annotations via the mirror API.

RELNOTES: N/A

fc961b490bef85f2e3f74eeff725949f544dd732


Work around b/118437729 RELNOTES: N/A

893ccba9c48e08cfe7335aaf54dd27c5cbf9840f


Deprecate ASTHelpers#getAnnotation

RELNOTES: N/A

013e2e3e70a9c556917f46cc5dd43e2b8b972497


Don't flag java.lang.Object in EqualsHashCode check

RELNOTES: Don't flag java.lang.Object in EqualsHashCode check

eebf07515fb792ec7482813d3065b0db10d3562b


Fix SwitchDefault suggested fix handling RELNOTES: N/A

8b69bb000f4de8b40e927a225fd8131471e6de23


Handle varargs parameters with no corresponding formals in Unused RELNOTES: N/A

354f565bb505293ccddeb192c72fb4341c57cfba


Fix a CCE in TruthAssertExpected RELNOTES: N/A

20d7285ab5d69430505e6e236b1181071197e1eb


Fix an NPE in JavaDurationGetSecondsGetNano RELNOTES: N/A

9373b6b9a15130f82aa9720daef7c8bf69016a3e


Fix an NPE RELNOTES: N/A

87d715e290813fb41a470bc159ad8b19f9951afd


Confirm that by default, MethodCanBeStatic only reports one finding for multiple fixes.

I don't see any coverage for this; the tests would have passed if it generated one per method.

RELNOTES: N/A

40bf3c00ff11bf37ef4ff4c030f4d7807855bdf1


Fix an NPE in EqualsGetClass.

RELNOTES: N/A

c8e07b3e7eddbcbaf0944eb21c7dd8f5245d162d


Fix a SIOOBE in Unused.

This occurs from confusing source positions when "int a, b;" is desugared into "int a; int b;".

RELNOTES: N/A

1a62b6fc4078c2b658b24dbe608cf65360d16787


Fix some brittle assumptions in MissingFail

RELNOTES: N/A

1174ad0d0ba7287ecec7d5dbc8f1c8f39d18db28


Fix a crash in DefaultCharset

if ByteString#copyFrom is called without a receiver.

RELNOTES: N/A

f7837f64856bec816739a803bba9f21366123e9b


Handle type attributes on class declarations

RELNOTES: N/A

036f805700572f417005a608973a170a46a1610b


Fix a crash in LockNotBeforeTry RELNOTES: N/A

174e29c8d73d3a4a1078d47376f7fa74737a6537


In TestExceptionChecker, don't crash on empty methods RELNOTES: N/A

1896778d4141318b5323a5e88d6a391fd63855ff


Fix a bug in ThreadSafety where not all type parameters at a method call are instantiated.

RELNOTES: none

31408892cadcbdae2359493b42ebd41c31881a7b

ronshapiro and others added 30 commits October 29, 2018 13:51
This should already be guaranteed by the getSymbolsByName method

RELNOTES: n/a

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=215568677
… methods. The isAssignable check fails against generic parameters, so limit the varargs boxing check to only happen when the parameter is actually a varargs parameter, instead of just applying the assignability check all the time.

RELNOTES: Fix for how NoAllocationChecker handles generic methods.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=215760282
…ic methods:

- don't propagate constraints from arguments to method results
- derive inference results more like javac, to find results more often

Generic method calls where actual types have type parameters can now sometimes not have an inference result, but previously those results came from propagation from arguments to results, which can in general lead to wrong results

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=215832970
instead of scanning the try/finally and direct cases as two separate
passes. Also check for re-opening the same lock, and don't move the
first acquisition down to the second acquisition's release.

RELNOTES: N/A

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=216059259
  {@code
    @OverRide
    public void foo();
  }

I can't find any way to escape an annotation within a {@code } tag. {@literal @} will be rendered exactly as written, as will &#64;.

Perhaps the only answer is to use <pre> and manually escape any HTML entities within the code block so that {@literal @} can be used?

RELNOTES: N/A

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=216334133
A summary line is required by the style guide on any public/protected Javadocs.

RELNOTES: Add Javadoc check for missing summary lines.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=216498548
…CamelCase when making a thread local suggestion.

ThreadLocal<java.text.DateFormat> is still mutable so constant casing seems wrong here.

RELNOTES:Change the DateFormatConstant bug checker to rename variable to lowerCamelCase when making a thread local suggestion.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=216765882
Also simplify the fix generation, and don't emit a suggestion if the class overrides *both* (that doesn't seem erroneous to me).

RELNOTES: Fixes in OverrideThrowableToString.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=216839302
Turns out that the crash was caused by static field imports -- they are JCFieldAccesses without a symbol.

RELNOTES: N/A

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=216911238
Per mockito/mockito#80 (comment), we
(the Mockito core team where I am a member of) do not support any usages of
org.mockito.internal.* To that end, we are free to change/add/remove any
methods/classes/interfaces in these packages.

Therefore, I propose we write an ErrorProne check that prohibits the usage
of such classes, as well as gradually remove all of these imports. This
should then greatly ease the process of upgrading Mockito to 2.*

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=217123327
…ugs.

RELNOTES: Add a number of static analysis checks around appropriate
use of java.time and org.joda.time classes - APIs that are unclear,
don't do what most people expect, or are otherwise easy to trip on.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=217139686
… as custom tags.

These seem not to be elevated to being canonical tags at this point, so this seems like the right home.

RELNOTES: Add java8 tags to InvalidTag.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=217290703
…hecker would crash on certain methods.

See test file for added regression tests with examples.

RELNOTES: Fix a few issues with the MutableMethodReturnType checker where the checker would crash on certain methods.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=217370430
sumitbhagwani and others added 15 commits October 29, 2018 17:26
RELNOTES: Don't flag java.lang.Object in EqualsHashCode check

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=218749708
RELNOTES: N/A

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=218798373
…or multiple fixes.

I don't see any coverage for this; the tests would have passed if it generated one per method.

RELNOTES: N/A

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=218840357
This occurs from confusing source positions when "int a, b;" is desugared into "int a; int b;".

RELNOTES: N/A

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=218883432
if ByteString#copyFrom is called without a receiver.

RELNOTES: N/A

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=218892281
@googlebot

Copy link
Copy Markdown
Collaborator

We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for all the commit author(s) or Co-authors. If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google.
In order to pass this check, please resolve this problem and have the pull request author add another comment and the bot will run again. If the bot doesn't comment, it means it doesn't think anything has changed.

@ronshapiro

Copy link
Copy Markdown
Contributor Author

All of the commits from non-googlers are from PRs that have CLAs signed.

@googlebot

Copy link
Copy Markdown
Collaborator

A Googler has manually verified that the CLAs look good.

(Googler, please make sure the reason for overriding the CLA status is clearly documented in these comments.)

@cushon cushon mentioned this pull request Nov 2, 2018
@cushon
cushon merged commit dd0faa2 into master Nov 2, 2018
@ronshapiro
ronshapiro deleted the sync-master-2018/10/29 branch December 24, 2018 04:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.