Skip to content

fix(id): address Santanu's review feedback on #109#112

Open
r0goyal wants to merge 1 commit into
id-v2from
id-v2-review-fixes
Open

fix(id): address Santanu's review feedback on #109#112
r0goyal wants to merge 1 commit into
id-v2from
id-v2-review-fixes

Conversation

@r0goyal

@r0goyal r0goyal commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Summary

Addresses actionable items from Santanu's review on #109.

Breaking-change concerns

  • IdValidationConstraint.isValid(Id) -> isValid(InternalId) (binary-breaking): restored isValid(Id) as the interface's abstract (compat-preserving) method. isValid(InternalId) is now a default method that bridges via new IdValidationConstraint.toId()/toInternalId() helpers, so existing external implementers keep compiling. PartitionValidator now overrides isValid(InternalId) directly (its natural contract) and implements isValid(Id) via the bridge.
  • IdGenerator.initialize(int, List, Map) removal: confirmed intentional, no change.
  • GenerationResult: documented as internal-only (Javadoc) - it's used across the generator/nonce subpackages so true package-private visibility isn't feasible without a larger restructure, but it's not meant to be treated as public API surface.

Design/correctness

  • IdGeneratorType.LOOKUP_MAP keyed by IdFormatter object identity: added IdFormatter.id() (stable string identifier implemented by DefaultIdFormatter/RandomNonceIdFormatter) and rekeyed the lookup map off that instead of raw instance identity. Closes the fragility completely - works even with a freshly constructed formatter of the same kind, not just the cached singletons.
  • IdParsersV2 DEFAULT_PATTERN ambiguity: added a comment explaining the two-step V1/V2 disambiguation (match, then require group(3) empty).
  • NodeUtils vs IdGeneratorBase re-set inconsistency: left as-is per discussion.
  • Dual registration burden (constraints registered separately on IdGenerator vs IdGeneratorV2): left as-is - callers using IdGeneratorV2 are expected to initialize it explicitly/independently.

Minor/style

  • Added missing Apache 2.0 license headers to the 9 flagged new files (+ GenerationResult.java).
  • Removed stale @SneakyThrows from IdGeneratorPerfTest/IdGeneratorPerfV2Test benchmark methods (no checked exceptions thrown).
  • Removed unused IdGeneratorBase import in IdParsersV2Test.
  • IdGenerationRequest (dead - no longer used by either generator) marked @deprecated with an explanatory Javadoc rather than removed outright, to avoid a silent source break for any external caller.

Tests

  • Added IdGeneratorV2Test#testV2IdParseWithLegacyGeneratorDoesNotRoundTrip, documenting the (lossy/asymmetric) interop contract: a legacy id parses fine via IdGeneratorV2.parse(), but a V2-generated id does not round-trip through the legacy IdGenerator.parse(), since it has no knowledge of the embedded IdGeneratorType code.
  • IdGeneratorV2.cleanUp() and IdGenerator.cleanUp() now both call NodeUtils.reset() (applied symmetrically since NodeUtils is shared state across both generators) - closes the latent footgun where a stale node id could be silently reused by a subsequent initialize().

Verification

  • mvn -pl ranger-discovery-bundle -am clean test - all test classes pass (0 failures/errors).

Base for review: this PR targets id-v2 (not main) so the diff can be reviewed/approved before folding into the main id-v2 branch feeding #109.

- IdValidationConstraint: restore isValid(Id) as the abstract method
  (binary-compat break flagged in review); isValid(InternalId) is now
  a default bridging via toInternalId()/toId() helpers
- GenerationResult: document as internal-only (not public API contract)
- IdFormatter: add id() so IdGeneratorType.LOOKUP_MAP keys off a stable
  identifier instead of formatter object identity, which only worked
  for the cached IdFormatters singletons
- IdParsersV2: comment DEFAULT_PATTERN's two-step V1/V2 disambiguation
- NodeUtils: add reset(), called from IdGenerator/IdGeneratorV2
  cleanUp() so a stale node id isn't silently reused by a later
  initialize() that forgets to call setNode() again
- add missing Apache license headers on 9 files
- drop stale @SneakyThrows from perf benchmarks, unused import in
  IdParsersV2Test, deprecate unused IdGenerationRequest
- add IdGeneratorV2Test covering the (asymmetric) V2->legacy parse
  interop contract

Refs review comments on #109

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@sonarqubecloud

sonarqubecloud Bot commented Jul 3, 2026

Copy link
Copy Markdown

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