Skip to content

Add compile-time DynamicClient usage check as an Error Prone BugChecker - #1305

Draft
mtdowling wants to merge 1 commit into
mainfrom
dynamic-client-errorprone
Draft

Add compile-time DynamicClient usage check as an Error Prone BugChecker#1305
mtdowling wants to merge 1 commit into
mainfrom
dynamic-client-errorprone

Conversation

@mtdowling

Copy link
Copy Markdown
Member

Validates DynamicClient usage against the Smithy model each client is actually built from, at compile time, without any code generation. The dynamic client stays fully runtime-driven and document-based; the check only reads the source under compilation.

The DynamicClientUsage BugChecker:

  • finds DynamicClient.builder()...build() chains and reads .model(...) and .serviceId(...) (handling ShapeId.from("..."));
  • statically resolves the model source by walking the Model.assembler() chain (addUnparsedModel/addImport/discoverModels, folding constants);
  • assembles that model in-process with the real smithy-model ModelAssembler (same code the runtime uses, no drift), cached per client;
  • checks each client.call("Op", Map.of(...)) site for a valid operation name (with a Levenshtein 'did you mean' SuggestedFix) and valid input member keys.

Core rule: abstain, never false-positive. Any genuinely dynamic value (runtime operation name, model passed in from elsewhere, addImport(url)) yields NO_MATCH, so runtime-dynamic usage like the CLI's SmithyCall is left alone.

The model-resolution core (ModelResolver, ResolvedClient, MapLiteral) is decoupled from the compiler via a constantResolver function. Verified Error Prone 2.50.0 runs under the project's Java 25 toolchain (needs the --add-exports/--add-opens set + --should-stop=ifError=FLOW; --release is dropped since it conflicts with --add-exports of a system module). Full :build passes: compile, spotless, javadoc, and 6 CompilationTestHelper tests covering unknown operation, bad input key, auto-detected service, and correct abstention on dynamic op name / unresolved model.

What behavior changes?

Describe the observable difference in behavior before and after this change.

Why is this change needed?

Explain the motivation: bug, feature request, refactor, performance, etc.

How was this validated?

List tests added, benchmarks run, or manual verification performed.

What should reviewers focus on?

Point reviewers to the files or sections that contain the interesting logic.

Additional Links

Related issues, design docs, or prior art.


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Validates DynamicClient usage against the Smithy model each client is
actually built from, at compile time, without any code generation. The
dynamic client stays fully runtime-driven and document-based; the check
only reads the source under compilation.

The DynamicClientUsage BugChecker:
- finds DynamicClient.builder()...build() chains and reads .model(...) and
  .serviceId(...) (handling ShapeId.from("..."));
- statically resolves the model source by walking the Model.assembler()
  chain (addUnparsedModel/addImport/discoverModels, folding constants);
- assembles that model in-process with the real smithy-model ModelAssembler
  (same code the runtime uses, no drift), cached per client;
- checks each client.call("Op", Map.of(...)) site for a valid operation
  name (with a Levenshtein 'did you mean' SuggestedFix) and valid input
  member keys.

Core rule: abstain, never false-positive. Any genuinely dynamic value
(runtime operation name, model passed in from elsewhere, addImport(url))
yields NO_MATCH, so runtime-dynamic usage like the CLI's SmithyCall is
left alone.

The model-resolution core (ModelResolver, ResolvedClient, MapLiteral) is
decoupled from the compiler via a constantResolver function. Verified
Error Prone 2.50.0 runs under the project's Java 25 toolchain (needs the
--add-exports/--add-opens set + --should-stop=ifError=FLOW; --release is
dropped since it conflicts with --add-exports of a system module). Full
:build passes: compile, spotless, javadoc, and 6 CompilationTestHelper
tests covering unknown operation, bad input key, auto-detected service,
and correct abstention on dynamic op name / unresolved model.
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