-
Notifications
You must be signed in to change notification settings - Fork 145
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
java.lang.RuntimeException: Unable to resolve #{male_first_name} directive for FakerContext #1178
Comments
2.2.2 snapshot? |
Are you working on a fix or hoping someone will pick this up? |
No, not 2.2.2-snapshot, 2.2.2-non-snapshot. It probably affects other versions too. And no, I'm not working on a fix at the moment. I had a look to see if I could find the issue, but so far I was a bit lost what's causing this. And yes, I would appreciate if a keen person for who it's not Sunday 9pm could have a look at this :-) |
Sorry, apparently I lost track of releases this week 😀 I'll try to have a look this week. |
Well, that's excusable: I did 3 releases in 3 days ;-). I'll also try to have a look when I'm a bit more fresh, thanks! |
It has something to do with chained or nested expressions. In en-AU name.first_name is a litteral list. In en-US (or well default) name.first_name is: first_name:
- "#{female_first_name}"
- "#{male_first_name}" If changed to: first_name:
- "#{name.female_first_name}"
- "#{name.male_first_name}" The tests pass. I'll have to keep testing/playing but I thought I should mention it in-case one of you sees the fix quicker knowing the code better than me 👍 Conversely the following test fails (seemingly for the same reason as the other English/default tests): @Test
void testExpressionNLWithMiddleWorks() {
Faker faker = new Faker(new Locale("nl", "nl"));
String expression = faker.expression("#{name.name_with_middle}");
System.out.println(expression);
} |
The issue seems to be "current" being passed as null:
The following makes the tests pass (obviously not a fix, but a PoC): diff --git a/src/main/java/net/datafaker/service/FakeValuesService.java b/src/main/java/net/datafaker/service/FakeValuesService.java
index daafc8dd..dd026bd3 100644
--- a/src/main/java/net/datafaker/service/FakeValuesService.java
+++ b/src/main/java/net/datafaker/service/FakeValuesService.java
@@ -1,5 +1,6 @@
package net.datafaker.service;
+import net.datafaker.Faker;
import net.datafaker.internal.helper.COWMap;
import net.datafaker.internal.helper.SingletonLocale;
import net.datafaker.providers.base.AbstractProvider;
@@ -547,6 +548,9 @@ protected String resolveExpression(String expression, Object current, ProviderRe
if (!expression.contains("}")) {
return expression;
}
+ if (current == null) {
+ current = new BaseFaker().name();
+ }
final int expressionLength = expression.length();
final String[] expressions = splitExpressions(expression, expressionLength);
final StringBuilder result = new StringBuilder(expressions.length * expressionLength); |
yep, the issue is with for instance for this test Faker faker = new Faker(new Locale("nl", "nl"));
faker.expression("#{address.full_address}"); the PoC code will fail |
Yeah that's why I said it wasn't a fix, just a poc |
#1180 |
@snuyanzin I've done some more tests, but things like this also don't work, no matter the Locale:
|
I added this test as well to the PR |
Describe the bug
Running the following code shows the issue:
Running this gives the following error:
To Reproduce
See above
Expected behavior
Generate a name
Versions:
Additional context
Add any other context about the problem here.
The text was updated successfully, but these errors were encountered: