serpro69 / kotlin-faker

Port of a popular ruby faker gem written in kotlin. Generate realistically looking fake data such as names, addresses, banking details, and many more, that can be used for testing and data anonymization purposes.
https://serpro69.github.io/kotlin-faker/
MIT License
468 stars 41 forks source link

Fake name not working #170

Closed Ragin-LundF closed 1 year ago

Ragin-LundF commented 1 year ago

Version: 1.12.0

Since 1.12.0, when I try to fake a name, I always get this exception. In 1.11.0 it worked:

null cannot be cast to non-null type kotlin.collections.Map<*, *>
java.lang.NullPointerException: null cannot be cast to non-null type kotlin.collections.Map<*, *>
    at io.github.serpro69.kfaker.FakerService.readCategoryOrNull(FakerService.kt:293)
    at io.github.serpro69.kfaker.FakerService.access$readCategoryOrNull(FakerService.kt:38)
    at io.github.serpro69.kfaker.FakerService$load$1.invoke(FakerService.kt:240)
    at io.github.serpro69.kfaker.FakerService$load$1.invoke(FakerService.kt:201)
    at io.github.serpro69.kfaker.FakerService.load$lambda$10(FakerService.kt:201)
    at java.base/java.util.Map.compute(Map.java:1171)
    at io.github.serpro69.kfaker.FakerService.load$core(FakerService.kt:201)
    at io.github.serpro69.kfaker.FakerService.load$core$default(FakerService.kt:198)
    at io.github.serpro69.kfaker.provider.Name.<init>(Name.kt:18)
    at io.github.serpro69.kfaker.Faker$name$2.invoke(Faker.kt:162)
    at io.github.serpro69.kfaker.Faker$name$2.invoke(Faker.kt:162)
    at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74)
    at io.github.serpro69.kfaker.Faker.getName(Faker.kt:162)

My code (reduced):

private val faker = Faker(config = fakerConfig { locale = "de-DE" })
faker.name.firstName()

Is this a bug or a feature?

serpro69 commented 1 year ago

Hi @Ragin-LundF ,

Thanks for reporting the issue. Not likely a feature, unless you want NPEs thrown at you :D I'll look into it over the weekend. Unless you'd like to submit a PR with a fix?

serpro69 commented 1 year ago

I think I've found the problem, but I want to add some tests for the fix and make sure it doesn't break anything else, so a new RC version with a fix is coming later this week.

For the time being, you can use "de" as locale, which should work fine on both 1.12.0 and latest RC of 1.13.0. It also produces exactly same values as "de-DE", since "de-DE" falls-back to using https://github.com/serpro69/kotlin-faker/blob/21e4183f5fe47e03900774e8ebf7a92c7a289533/core/src/main/resources/locales/de.yml dict file anyways.

Ragin-LundF commented 1 year ago

Thank you so much for analyzing the issue so fast. locale "de" worked fine ;).

serpro69 commented 1 year ago

FYI, the fix is available in 1.13.0-rc.3, if you want to go back to using de-DE locale.