Skip to content

Annotate comparison methods as @Pure - #294

Merged
mernst merged 10 commits into
typetools:masterfrom
mernst:comparator-compare-pure
Sep 20, 2026
Merged

mernst merged 10 commits into
typetools:masterfrom
mernst:comparator-compare-pure

Conversation

@mernst

@mernst mernst commented Sep 18, 2026 •

Copy link
Copy Markdown
Member

mernst and others added 9 commits September 18, 2026 10:00
Annotate all overrides of `Comparable.compareTo` in files that import
Checker Framework annotations.  `StringBuilder.compareTo` and
`StringBuffer.compareTo` are upgraded from `@SideEffectFree` to `@Pure`.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Annotate the remaining 125 overrides of `Object.equals` in files that
import Checker Framework annotations.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Annotate the remaining comparison methods in files that import Checker
Framework annotations: `isEqual`, `isBefore`, `isAfter`, `before`,
`after`, `regionMatches`, `equalsIgnoreCase`, `contentEquals`,
`mismatch`, `signum`, and the non-`Comparator` `compare` overloads.

`Predicate.isEqual` is annotated `@SideEffectFree` rather than `@Pure`:
it is a factory that returns a fresh lambda, so it is not deterministic.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
`Executable.java` and `Member.java` use `@Pure` and `@SideEffectFree`
without importing them, which breaks compilation.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Class.getMethod, getConstructor, getDeclaredField, getDeclaredMethod,
and getDeclaredConstructor each end in a copyMethod/copyField/
copyConstructor call, so they return a freshly allocated object on
every call and are not deterministic.

Method.getTypeParameters and Method.getDeclaredAnnotations likewise
return a new array on every call.

Method.specificToStringHeader and specificToGenericStringHeader append
to their StringBuilder parameter, so they are not side-effect-free
either; remove the annotation rather than weakening it.
@mernst
mernst merged commit 6688d3b into typetools:master Sep 20, 2026
49 checks passed
@mernst
mernst deleted the comparator-compare-pure branch September 20, 2026 07:43
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