Skip to content

Commit 6dcb06e

Browse files
mferretticlaude
authored andcommitted
Add null-root guards to remaining L1 resolvers
RootCoercedResolver, NamedProviderCoercedResolver, and ChainedCoercedResolver all called root.getProvider() / fakerAccessor.invoke(root) without guarding against null root in both resolve() and materialize(). Pattern matches the existing guards on SafeFetchResolver and ProviderMethodResolver. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent df112f1 commit 6dcb06e

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1246,11 +1246,13 @@ public String toString() {
12461246
private record RootCoercedResolver(MethodAndCoercedArgs accessor) implements ValueResolver {
12471247
@Override
12481248
public Object resolve(ProviderRegistration root, FakerContext context) {
1249+
if (root == null) return null;
12491250
return invokeCoerced(accessor, root);
12501251
}
12511252

12521253
@Override
12531254
public ValueResolver materialize(ProviderRegistration root) {
1255+
if (root == null) return this;
12541256
return new InstanceCoercedResolver(accessor, root);
12551257
}
12561258
}
@@ -1259,11 +1261,13 @@ public ValueResolver materialize(ProviderRegistration root) {
12591261
private record NamedProviderCoercedResolver(String providerName, MethodAndCoercedArgs accessor) implements ValueResolver {
12601262
@Override
12611263
public Object resolve(ProviderRegistration root, FakerContext context) {
1264+
if (root == null) return null;
12621265
return invokeCoerced(accessor, root.getProvider(providerName));
12631266
}
12641267

12651268
@Override
12661269
public ValueResolver materialize(ProviderRegistration root) {
1270+
if (root == null) return this;
12671271
return new InstanceCoercedResolver(accessor, root.getProvider(providerName));
12681272
}
12691273
}
@@ -1272,6 +1276,7 @@ public ValueResolver materialize(ProviderRegistration root) {
12721276
private record ChainedCoercedResolver(MethodAndCoercedArgs fakerAccessor, MethodAndCoercedArgs accessor) implements ValueResolver {
12731277
@Override
12741278
public Object resolve(ProviderRegistration root, FakerContext context) {
1279+
if (root == null) return null;
12751280
try {
12761281
return invokeCoerced(accessor, fakerAccessor.invoke(root));
12771282
} catch (InvocationTargetException | IllegalAccessException e) {
@@ -1281,6 +1286,7 @@ public Object resolve(ProviderRegistration root, FakerContext context) {
12811286

12821287
@Override
12831288
public ValueResolver materialize(ProviderRegistration root) {
1289+
if (root == null) return this;
12841290
try {
12851291
return new InstanceCoercedResolver(accessor, fakerAccessor.invoke(root));
12861292
} catch (InvocationTargetException | IllegalAccessException e) {

0 commit comments

Comments
 (0)