docs: fix inaccuracies in README code examples#1931
docs: fix inaccuracies in README code examples#1931jonathannorris wants to merge 1 commit intomainfrom
Conversation
There was a problem hiding this comment.
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.
Signed-off-by: Jonathan Norris <jonathan.norris@dynatrace.com>
0a7d379 to
eba3402
Compare
There was a problem hiding this comment.
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.
|
|
The raw-type version compiles but emits 12 |
Codecov Report✅ All modified and coverable lines are covered by tests. 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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|



Summary
Changes
System.getEnv("us-east-1")(both occurrences). The method isSystem.getenv(...)(lowercasee—getEnvdoes not exist in Java). The argument was also wrong —"us-east-1"is a region value, not an env var name. Changed toSystem.getenv("AWS_REGION")which reads the region from the environment variableapi.getInstance().getClient()toapi.getClient(). CallinggetInstance()(a static method) through theapiinstance reference is redundant sinceapiwas already assigned the singleton on the line abovenewkeyword insetProvider(LocalProvider())— withoutnew, Java parses it as a method call to a nonexistent staticLocalProvider()method, causing a compile errorHook<T>interface signatures:Hook->Hook<Object>HookContext ctx->HookContext<Object> ctxMap hints->Map<String, Object> hintsOptional(return ofbefore) ->Optional<EvaluationContext>FlagEvaluationDetails details->FlagEvaluationDetails<Object> detailsreturn Optional.empty();tobefore(). Once the return type is parameterized asOptional<EvaluationContext>(instead of rawOptional), a missing return becomes a compile error rather than silently compilingAll fixed examples were verified to compile cleanly against the current main branch. Original broken versions were confirmed to fail compilation.