Skip to content

Commit 6c1f78a

Browse files
fix: don't try to process a non-match as a binary incompatibility.
1 parent c0da958 commit 6c1f78a

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/functionalTest/groovy/com/autonomousapps/jvm/DuplicateClasspathSpec.groovy

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import static com.google.common.truth.Truth.assertThat
1414

1515
final class DuplicateClasspathSpec extends AbstractJvmSpec {
1616

17+
// TODO(tsr): missing test for when there's duplication and all accesses are in fact compatible.
18+
1719
def "duplicates on the classpath can be fixed (#gradleVersion)"() {
1820
given:
1921
def project = new DuplicateClasspathProject()

src/main/kotlin/com/autonomousapps/internal/binary/BinaryCompatibilityChecker.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,14 @@ internal class BinaryCompatibilityChecker(
7373
val relevantMemberAccesses = context.project.memberAccesses
7474
.filterToOrderedSet { access -> access.owner in relevantDuplicateClassNames }
7575

76+
if (relevantMemberAccesses.isEmpty()) return null
77+
7678
val (matchingBinaryClasses, nonMatchingBinaryClasses) = relevantMemberAccesses.mapToSet { access ->
7779
binaryClassCapability.findMatchingClasses(access)
7880
}.reduce()
7981

82+
if (nonMatchingBinaryClasses.isEmpty()) return null
83+
8084
// There must be a compatible BinaryClass.<field|method> for each MemberAccess for the usage to be binary-compatible
8185
val isBinaryCompatible = relevantMemberAccesses.all { access ->
8286
when (access) {
@@ -204,11 +208,11 @@ internal class BinaryCompatibilityChecker(
204208
* it's only called on "relevant" classes. THIS class, however, can, via [findRelevantBinaryClasses].
205209
*/
206210
private fun BinaryClass.partition(memberAccess: MemberAccess): Pair<BinaryClass?, BinaryClass?> {
207-
// There can be only one match
211+
// There can be only one match: [0, 1]
208212
val matchingFields = effectivelyPublicFields.firstOrNull { it.matches(memberAccess) }
209213
val matchingMethods = effectivelyPublicMethods.firstOrNull { it.matches(memberAccess) }
210214

211-
// There can be many non-matches
215+
// There can be many non-matches: [0, ∞]
212216
val nonMatchingFields = effectivelyPublicFields.filterToOrderedSet { it.doesNotMatch(memberAccess) }
213217
val nonMatchingMethods = effectivelyPublicMethods.filterToOrderedSet { it.doesNotMatch(memberAccess) }
214218

0 commit comments

Comments
 (0)