davsclaus commented on code in PR #27679:
URL: https://github.com/apache/camel/pull/27679#discussion_r4240667208
##########
components/camel-hashicorp-vault/src/main/java/org/apache/camel/component/hashicorp/vault/HashicorpVaultPropertiesFunction.java:
##########
@@ -247,11 +257,14 @@ private String getSecretFromSource(String key, String
subkey, String defaultValu
}
}
if (ObjectHelper.isNotEmpty(subkey)) {
- Object field = ((Map)
rawSecret.getData().get("data")).get(subkey);
- if (ObjectHelper.isNotEmpty(field)) {
- returnValue = field.toString();
- } else {
- returnValue = null;
+ returnValue = null;
+ // the secret may not exist, then there is no field either
+ if (rawSecret != null && rawSecret.getData() != null
+ && rawSecret.getData().get("data") instanceof Map<?,
?> data) {
+ Object field = data.get(subkey);
+ if (ObjectHelper.isNotEmpty(field)) {
+ returnValue = field.toString();
+ }
}
}
if (ObjectHelper.isEmpty(returnValue)) {
Review Comment:
Thanks, good catch: applied in e9c57b372727 rather than in a follow-up. Both
paths now read the secret data once, null-safe (`rawSecret` → `getData()` →
`get("data")`), so a response without data resolves to no value (or the default
value) also without a field, and `captureVersion` takes the response data map,
so it cannot NPE on it either.
New test `responseWithoutDataReturnsNullOrDefaultValue` covers a response
without data and a response with only metadata, with and without field/default
value; it fails with the `NullPointerException` on the previous commit.
_Claude Code on behalf of davsclaus_
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]