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

NullPointerException after upgrading to 0.17

Open wakramp opened this issue 7 years ago • 8 comments

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?

wakramp avatar Feb 01 '19 12:02 wakramp

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 avatar Feb 01 '19 20:02 thuri

@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.

codingricky avatar Feb 02 '19 00:02 codingricky

I'm still seeing it in 0.17.1

rspieldenner avatar Feb 02 '19 01:02 rspieldenner

@rspieldenner could I get more details? which locale? which method? which jvm? which OS?

codingricky avatar Feb 02 '19 01:02 codingricky

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)

rspieldenner avatar Feb 02 '19 01:02 rspieldenner

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 avatar Feb 02 '19 01:02 rspieldenner

@rspieldenner cool thanks for letting me know, I was struggling to reproduce it.

codingricky avatar Feb 02 '19 01:02 codingricky

Yep, the fix works for me too.

Thanks for the quick response and fix :+1:

wakramp avatar Feb 04 '19 07:02 wakramp