Skip to content

docs: fix inaccuracies in README code examples#1931

Open
jonathannorris wants to merge 1 commit intomainfrom
fix/readme-accuracy
Open

docs: fix inaccuracies in README code examples#1931
jonathannorris wants to merge 1 commit intomainfrom
fix/readme-accuracy

Conversation

@jonathannorris
Copy link
Copy Markdown
Member

@jonathannorris jonathannorris commented Apr 20, 2026

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.

Copy link
Copy Markdown
Contributor

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

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
Signed-off-by: Jonathan Norris <jonathan.norris@dynatrace.com>
Copy link
Copy Markdown

Copilot AI left a comment

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
@sonarqubecloud
Copy link
Copy Markdown

@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
Copy link
Copy Markdown

codecov Bot commented Apr 20, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.26%. Comparing base (b683371) to head (eba3402).

Additional details and impacted files
@@             Coverage Diff              @@
##               main    #1931      +/-   ##
============================================
+ Coverage     92.25%   93.26%   +1.00%     
- Complexity      653      656       +3     
============================================
  Files            59       59              
  Lines          1589     1589              
  Branches        179      179              
============================================
+ Hits           1466     1482      +16     
+ Misses           76       62      -14     
+ Partials         47       45       -2     
Flag Coverage Δ
unittests 93.26% <ø> (+1.00%) ⬆️

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

☔ View full report in Codecov by Sentry.
📢 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 April 20, 2026 19:11
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.

2 participants