8000 Use Guava for Preconditions and Verify by andrewaylett · Pull Request #114 · andrewaylett/arc · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Use Guava for Preconditions and Verify #114

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

Merged
merged 1 commit into from
May 31, 2025
Merged

Conversation

andrewaylett
Copy link
Owner

I'm a smidge reluctant to add an implementation dependency, but the Guava utilities are useful enough to make it worthwhile.

I'm a smidge reluctant to add an implementation dependency, but the
Guava utilities are useful enough to make it worthwhile.
@Copilot Copilot AI review requested due to automatic review settings May 31, 2025 17:26
Copy link
@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces Guava as a new dependency to replace the custom Invariants utility, migrating assertion logic to Guava’s Preconditions and Verify, and updating build/configuration files accordingly.

  • Add Guava dependency and replace custom null‐checks and invariant throws with Preconditions.checkArgument, checkNotNull, and Verify.verify.
  • Remove the Invariants class and deprecated isForExpiredElements() methods, updating safety checks across lists and InnerArc.
  • Update module‐info, Gradle setup, and Checkstyle rules to include Guava and ban legacy nullness annotations.

Reviewed Changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
lib/src/main/java/module-info.java Added requires com.google.common module
lib/src/main/java/eu/aylett/arc/internal/UnownedElementList.java Removed unused override of isForExpiredElements()
lib/src/main/java/eu/aylett/arc/internal/LRUElementList.java Replaced manual IllegalStateException checks with verify
lib/src/main/java/eu/aylett/arc/internal/ExpiredElementList.java Swapped manual throws for Guava verify/checkArgument
lib/src/main/java/eu/aylett/arc/internal/Invariants.java Deleted obsolete custom assertions class
lib/src/main/java/eu/aylett/arc/internal/InnerArc.java Imported Guava verify, added unowned.checkSafety() call
lib/src/main/java/eu/aylett/arc/internal/ElementList.java Removed abstract isForExpiredElements()
lib/src/main/java/eu/aylett/arc/internal/Element.java Switched to JSPECIFY @NonNull & Guava verify in get()
lib/src/main/java/eu/aylett/arc/Arc.java Swapped argument checks to Guava checkArgument/checkNotNull, added Javadoc for runEviction
lib/build.gradle.kts Changed several dependencies to api and added implementation(libs.guava)
gradle/libs.versions.toml Added Guava version and module entries
config/checkstyle/checkstyle.xml Introduced IllegalImport rule for legacy nullness annots
Comments suppressed due to low confidence (2)

lib/src/main/java/eu/aylett/arc/internal/LRUElementList.java:89

  • [nitpick] The variable name startSize differs from initialSize in ExpiredElementList. Consider using a consistent name (e.g., initialSize) across both implementations for clarity.
verify(seen.size() == startSize, "Size mismatch: found %s items != expected %s", seen.size(), startSize);

lib/src/main/java/eu/aylett/arc/internal/InnerArc.java:119

  • New call to unowned.checkSafety() was added but no tests have been updated. Consider adding unit tests to cover the safety checks for the UnownedElementList.
    unowned.checkSafety();

throw new IllegalStateException("Called get on an object in an expired list");
}
verify(currentOwner != unowned, "Called get on an element with no owner");
verify(currentOwner instanceof LRUElementList, "Called get on an object in an expired list");
Copy link
Preview
Copilot AI May 31, 2025

Choose a reason for hiding this comment

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

Relying on instanceof LRUElementList couples the check to a specific implementation. Consider restoring an explicit method (e.g., isForExpiredElements()) or adding a boolean flag in the ElementList hierarchy to detect expired lists more generically.

Copilot uses AI. Check for mistakes.

@@ -223,6 +217,19 @@ public void checkSafety() {
}
}

/**
Copy link
Preview
Copilot AI May 31, 2025

Choose a reason for hiding this comment

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

The runEviction method has a detailed Javadoc but lacks thread‐safety annotations (e.g., @GuardedBy) or clearer lock usage notes. Consider annotating which lock is held or required to align with the rest of the class’s conventions.

Copilot uses AI. Check for mistakes.

@andrewaylett andrewaylett merged commit 70136cc into main May 31, 2025
5 checks passed
@andrewaylett andrewaylett deleted the push-znzptlsqpzrl branch May 31, 2025 17:28
Copy link
  • Surviving mutants in this change: 40
  • Killed mutants in this change: 13
class surviving killed
🧟eu.aylett.arc.internal.ExpiredElementList 12 5
🧟eu.aylett.arc.internal.LRUElementList 12 3
🧟eu.aylett.arc.Arc 7 1
🧟eu.aylett.arc.internal.InnerArc 6 3
🧟eu.aylett.arc.internal.Element 3 1

See https://pitest.org

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant
0