Skip to content

docs: fix inaccuracies in README code examples#1931

Merged
toddbaert merged 1 commit into
mainfrom
fix/readme-accuracy
Jun 18, 2026
Merged

docs: fix inaccuracies in README code examples#1931
toddbaert merged 1 commit into
mainfrom
fix/readme-accuracy

Conversation

@jonathannorris

@jonathannorris jonathannorris commented Apr 20, 2026

Copy link
Copy Markdown
Member

Summary

  • Fix multiple code examples in the README that would fail to compile as written

Changes

  1. Targeting section: Fixed System.getEnv("us-east-1") (both occurrences). The method is System.getenv(...) (lowercase egetEnv does not exist in Java). The argument was also wrong — "us-east-1" is a region value, not an env var name. Changed to System.getenv("AWS_REGION") which reads the region from the environment variable
  2. Targeting section: Simplified api.getInstance().getClient() to api.getClient(). Calling getInstance() (a static method) through the api instance reference is redundant since api was already assigned the singleton on the line above
  3. Domains section: Added missing new keyword in setProvider(LocalProvider()) — without new, Java parses it as a method call to a nonexistent static LocalProvider() method, causing a compile error
  4. Hook example: Parameterized all raw types to match the actual Hook<T> interface signatures:
    • Hook -> Hook<Object>
    • HookContext ctx -> HookContext<Object> ctx
    • Map hints -> Map<String, Object> hints
    • Optional (return of before) -> Optional<EvaluationContext>
    • FlagEvaluationDetails details -> FlagEvaluationDetails<Object> details
  5. Hook example: Added return Optional.empty(); to before(). Once the return type is parameterized as Optional<EvaluationContext> (instead of raw Optional), a missing return becomes a compile error rather than silently compiling

All fixed examples were verified to compile cleanly against the current main branch. Original broken versions were confirmed to fail compilation.

Summary by CodeRabbit

  • Documentation
    • Updated targeting configuration example to read region from environment variables instead of hardcoded values
    • Updated domain provider registration example with clearer syntax patterns
    • Updated hook development example with improved type safety using generics and typed interfaces

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request updates the README.md to correct environment variable usage, simplify API calls, and fix a missing 'new' keyword in a provider instantiation. It also updates the Hook implementation example to include generic types. A review comment correctly identified that the 'before' method in the Hook example is missing a return statement, which would cause a compilation error.

Comment thread README.md

Copilot AI left a comment

Copy link
Copy Markdown

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 updates the README’s Java snippets to better reflect the actual Java SDK APIs and to avoid compilation issues in the documentation examples.

Changes:

  • Fix incorrect usage of Java environment variable APIs in the targeting example.
  • Simplify client acquisition to use api.getClient() directly.
  • Update hook example signatures to match the generic Hook<T> interface.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread README.md
Comment thread README.md
Comment thread README.md
@jonathannorris

Copy link
Copy Markdown
Member Author

The raw-type version compiles but emits 12 [rawtypes] warnings under javac -Xlint:all. Parameterizing to match the actual Hook<T> interface signatures gives users a correct template to copy without warnings, and reflects how the interface is actually defined.

@codecov

codecov Bot commented Apr 20, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.10%. Comparing base (3a05490) to head (e7e148f).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff              @@
##               main    #1931      +/-   ##
============================================
+ Coverage     92.11%   93.10%   +0.98%     
- Complexity      660      663       +3     
============================================
  Files            59       59              
  Lines          1624     1624              
  Branches        182      182              
============================================
+ Hits           1496     1512      +16     
+ Misses           80       66      -14     
+ Partials         48       46       -2     
Flag Coverage Δ
unittests 93.10% <ø> (+0.98%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jonathannorris jonathannorris requested review from a team, beeme1mr and toddbaert April 20, 2026 19:11
@jonathannorris jonathannorris force-pushed the fix/readme-accuracy branch from b7ac0b0 to bd53036 Compare May 5, 2026 17:50
@sonarqubecloud

sonarqubecloud Bot commented May 5, 2026

Copy link
Copy Markdown

Signed-off-by: Jonathan Norris <jonathan.norris@dynatrace.com>
@toddbaert toddbaert force-pushed the fix/readme-accuracy branch from bd53036 to e7e148f Compare June 18, 2026 21:17
@coderabbitai

coderabbitai Bot commented Jun 18, 2026

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 98d7b48f-3ba0-46ee-a724-46dc9c58c686

📥 Commits

Reviewing files that changed from the base of the PR and between 3a05490 and e7e148f.

📒 Files selected for processing (1)
  • README.md

📝 Walkthrough

Walkthrough

Three Java code snippets in README.md are corrected: the Targeting example fixes the environment variable method name and reads AWS_REGION, the Domains example adds the missing new keyword for provider instantiation, and the Hook example is updated to use the typed generic Hook<Object> interface with proper signatures.

Changes

README Snippet Corrections

Layer / File(s) Summary
Targeting, Domains, and Hook example corrections
README.md
Targeting snippet replaces System.getEnv("us-east-1") with System.getenv("AWS_REGION") and retrieves the client via api.getClient(). Domains snippet corrects LocalProvider() to new LocalProvider(). Hook snippet replaces raw Hook with typed Hook<Object>, adding HookContext<Object>, Map<String, Object> hints, and a typed before method returning Optional<EvaluationContext>.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes


Comment @coderabbitai help to get the list of available commands and usage tips.

@toddbaert toddbaert merged commit cc837b1 into main Jun 18, 2026
5 of 6 checks passed
@toddbaert toddbaert deleted the fix/readme-accuracy branch June 18, 2026 21:17
@sonarqubecloud

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.

4 participants