Repository navigation
Compare types with TypeUtils.isOfType instead of JavaType.equals - #1252
Merged
Merged
Conversation
openrewrite/rewrite is removing the equals overrides from JavaType, which would silently turn these comparisons into identity checks. This covers direct equals calls as well as Objects.equals, List.equals and Map.containsValue on types.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Six
JavaTypeclasses overrideequalswithouthashCode, so aHashSetorHashMapkeyed on types matches by identity whileequalsmatches by name. openrewrite/rewrite is removing thoseequalsoverrides. Fifteen classes here compare types by value in 29 places, and each of those comparisons would silently become an identity check.This switches them to
TypeUtils.isOfType, which already exists, so it can merge ahead of the rewrite change:Six of the sites are not plain
equalscalls. FourObjects.equalscalls becomeisOfTypeas well. TheList.equalsover parameter types inAssertTrueNegationToAssertFalsebecomes an element-wiseisOfType, and theMap.containsValueinJMockitMockUpToMockitobecomes anoneMatchover the map's values.isOfTypeis not a drop-in copy ofequals:JavaType.Variables, andisOfTypealso compares the variable's type. Two separate instances of a field typedJavaType.Unknownno longer match, though the parser normally shares one instance per field.RemoveInitMocksIfRunnersSpecifiedadmits such fields as possible handle receivers.Methodalso compares flags and thrown exceptions, which matters only forJMockitMockUpToMockito.Sets of variables in
ExpectedSystemExitToCatchSystemExitandRemoveDoNothingForDefaultMocksare left alone. They hash by identity today and keep doing so.The existing tests of the touched classes, 251 in 25 classes, pass against the current rewrite snapshot and against a local
rewrite-javabuild without theequalsoverrides. FiveSystemRulesMigrationTestcases could not run, because Maven Central answered their downloads with HTTP 429. Unchangedmainpasses against that build too, so no test exercises a case where value and identity differ.