java-faker icon indicating copy to clipboard operation
java-faker copied to clipboard

NPE for IBAN with country code

Open manosbatsis opened this issue 2 years ago • 2 comments

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:

  • JDK Runtime Environment (build 17.0.8.1+1-Ubuntu-0ubuntu122.04)
  • Faker Version 1.0.2

manosbatsis avatar Oct 26 '23 10:10 manosbatsis

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.

manosbatsis avatar Oct 27 '23 08:10 manosbatsis

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

bodiam avatar Oct 27 '23 08:10 bodiam