Athiban Studio
Athiban Studio

Reputation: 11

getResourceAsStream returns null under Thread.currentThread.getContextClassLoader().getClass()

So The currently the loading configuration used by the library is

ClassLoader loader = Thread.currentThread().getContextClassLoader();
InputStream in = loader.getClass().getResourceAsStream("/properties/a.properties") // null

But when I tried to debug the application, the following expression contains the file

loader.getResourceAsStream("properties/a.properties")

I am using IntelliJ IDE and Maven build tool. The resources are copied into the target folder. And using IntelliJ run command to run the class currently.

Since the code is from the library, I can't modify it. What is the problem here and how it can be solved?

Upvotes: 1

Views: 416

Answers (1)

Athiban Studio
Athiban Studio

Reputation: 11

One possible workaround is to downgrade the Java version to a non-module version (less than 9), so that the code works.

Upvotes: 0

Related Questions