DiUS / java-faker

Brings the popular ruby faker gem to Java
http://dius.github.io/java-faker
Other
4.77k stars 851 forks source link

NPE for IBAN with country code #767

Open manosbatsis opened 1 year ago

manosbatsis commented 1 year ago

Trying to get an IBAN using a country code provided by Faker itself results to a null pointer, e.g.

faker.finance().iban(faker.country().countryCode2())

Gives:

java.lang.NullPointerException: Cannot invoke "String.length()" because "str" is null
        at java.base/java.lang.AbstractStringBuilder.<init>(AbstractStringBuilder.java:105) ~[na:na]
        at java.base/java.lang.StringBuilder.<init>(StringBuilder.java:131) ~[na:na]
        at com.mifmif.common.regex.Generex.requote(Generex.java:417) ~[generex-1.0.2.jar:1.0.2]
        at com.mifmif.common.regex.Generex.<init>(Generex.java:84) ~[generex-1.0.2.jar:1.0.2]
        at com.mifmif.common.regex.Generex.<init>(Generex.java:76) ~[generex-1.0.2.jar:1.0.2]
        at com.github.javafaker.service.FakeValuesService.regexify(FakeValuesService.java:252) ~[javafaker-1.0.2.jar:na]
        at com.github.javafaker.Faker.regexify(Faker.java:310) ~[javafaker-1.0.2.jar:na]
        at com.github.javafaker.Finance.iban(Finance.java:64) ~[javafaker-1.0.2.jar:na]

Versions:

manosbatsis commented 1 year ago

My suggestion would be to make Finance.countryCodeToBasicBankAccountNumberPattern public or add a method to access it's keys so they can be used for random selection of a country scope.

bodiam commented 1 year ago

@manosbatsis this issue has been fixed in Datafaker, an active fork of Javafaker: https://github.com/datafaker-net/datafaker