A CacheDirective built by a factory is not equal to the same directive parsed from a header
Problem
CacheDirective has a boolean digit attribute ("the value is a number"). It is set to true by the factories that take a number (maxAge, maxStale(int), minFresh, sharedMaxAge, staleWhileRevalidate, staleIfError), through new CacheDirective(name, value, true). A directive read from a Cache-Control header is created by the header reader through the (name, value) constructor, so its digit is false.
equals and hashCode take digit into account, so:
CacheDirective.maxAge(60).equals(<the max-age=60 directive parsed from a Cache-Control header>) // false
A contains, remove or Set that mixes directives built by the application and directives parsed from a message silently misses, and a test that compares a parsed header with CacheDirective.maxAge(60) fails.
Why the attribute should not take part in equality
digit is not used when writing the header: CacheDirectiveWriter quotes the value of no-cache / private as RFC 9111 §5.2.2.4 and §5.2.2.7 require, and writes any other value as a token or, if it is not a token, as a quoted-string (HeaderWriter.appendExtension). The only uses of isDigit() are hashCode, the getter and toString. It is a hint that two directives with the same name and value can disagree on.
Affects 3.0, 2.7 and 2.6 (same code).
Proposal
equalsandhashCodeuse the name and the value only (all versions).digititself is useless: deprecateisDigit(),setDigit(boolean)and the three-argument constructor in 2.x, and remove them in 3.0.