NullPointerException after upgrading to 0.17
Hi,
after upgrading from 0.16 to 0.17 I get a NullPointerException when I do new Faker()
java.lang.NullPointerException
at com.github.javafaker.service.FakeValuesService.<init>(FakeValuesService.java:74)
at com.github.javafaker.Faker.<init>(Faker.java:101)
at com.github.javafaker.Faker.<init>(Faker.java:92)
at com.github.javafaker.Faker.<init>(Faker.java:88)
Anything I missed for upgrading to the new version?
I do have the same problem. Looks like commit https://github.com/DiUS/java-faker/commit/1fae9ce05e50537af3d15ea348c2949dec43d06a has introduced some hidden NPE the line
return (url != null) ? new File(url.getPath()).listFiles() : new File[0];
contains the call to listFiles which returns null in case the path doesn't denote a directory. From the java doc:
If this abstract pathname does not denote a directory, then this method returns null
@codingricky Where did you want the code to look for the direcotry "en"? Because i think that getClass().getClassLoader() will return the jar class loader and look for the directory in the jar.
For example the url has the following value within the method listFilesInDirectoryOnClasspath when i run my test using faker as a maven dependency.
jar:file:/home/thuri/.m2/repository/com/github/javafaker/javafaker/0.17/javafaker-0.17.jar!/en
@thuri @waldkram try the latest version, I added a fix. It's quite tricky to test as the tests don't replicate exactly the same situation as at runtime. I had to create another project and use the faker as a dependency to replicate it.
I'm still seeing it in 0.17.1
@rspieldenner could I get more details? which locale? which method? which jvm? which OS?
Caused by: java.lang.NullPointerException
at com.github.javafaker.service.FakeValuesService.<init>(FakeValuesService.java:74)
at com.github.javafaker.Faker.<init>(Faker.java:101)
at com.github.javafaker.Faker.<init>(Faker.java:92)
at com.github.javafaker.Faker.<init>(Faker.java:88)
thrown from my code by private static final Faker FAKER = new Faker();
macOs Mojave 10.14.3 locale en java
openjdk version "1.8.0_201"
OpenJDK Runtime Environment (Zulu 8.34.0.1-CA-macosx) (build 1.8.0_201-b10)
OpenJDK 64-Bit Server VM (Zulu 8.34.0.1-CA-macosx) (build 25.201-b10, mixed mode)
and apologies, my dependency update got stuck on 0.17 when i went back from 0.16 to 0.+ -- I'm fixed at 0.17.1
@rspieldenner cool thanks for letting me know, I was struggling to reproduce it.
Yep, the fix works for me too.
Thanks for the quick response and fix :+1: