Skip to content

Commit df112f1

Browse files
mferretticlaude
authored andcommitted
Guard null root in ProviderMethodResolver and outer materialize calls
- ProviderMethodResolver.resolve(): return null when root is null - ProviderMethodResolver.materialize(): return this when root is null - resolveExpression outer loop: skip L2 caching when root is null, call recipe directly without materializing Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent c013812 commit df112f1

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

src/main/java/net/datafaker/service/FakeValuesService.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -612,8 +612,8 @@ protected String resolveExpression(String expression, Object current, ProviderRe
612612
// L1: static recipe hit — materialize once, store in L2
613613
final ValueResolver recipe = RECIPE_MAP.get(cacheKey);
614614
if (recipe != null) {
615-
final ValueResolver materialized = recipe.materialize(root);
616-
instanceMap.put(expr, materialized);
615+
final ValueResolver materialized = root != null ? recipe.materialize(root) : recipe;
616+
if (root != null) instanceMap.put(expr, materialized);
617617
resolved = materialized.resolve(root, context);
618618
} else {
619619
// Both miss: full discovery
@@ -627,7 +627,7 @@ protected String resolveExpression(String expression, Object current, ProviderRe
627627
resolved = resolveExpression(directive, args, current, root, context, cacheKey);
628628
// resolveExpression stored recipe in RECIPE_MAP if cacheable; materialize for L2
629629
final ValueResolver stored = RECIPE_MAP.get(cacheKey);
630-
if (stored != null) {
630+
if (stored != null && root != null) {
631631
instanceMap.put(expr, stored.materialize(root));
632632
}
633633
}
@@ -1225,11 +1225,13 @@ public Object resolve(ProviderRegistration root, FakerContext context) {
12251225
private record ProviderMethodResolver(String providerName, Method method, Object[] args) implements ValueResolver {
12261226
@Override
12271227
public Object resolve(ProviderRegistration root, FakerContext context) {
1228+
if (root == null) return null;
12281229
return new InstanceMethodResolver(root.getProvider(providerName), method, args).resolve(root, context);
12291230
}
12301231

12311232
@Override
12321233
public ValueResolver materialize(ProviderRegistration root) {
1234+
if (root == null) return this;
12331235
return new InstanceMethodResolver(root.getProvider(providerName), method, args);
12341236
}
12351237

0 commit comments

Comments
 (0)