Why path on server throw NullPonterException?

Viewed 28

I have a problem with the path to the file. Locally (Windows), the tests pass, but when I upload it to the server(Linux), I have:

NullPointerException: Cannot get property 'text' on null object

Sample code:

public final String MAIN = "dir1/dir2/dir3/"
public final String CAT_1 = MAIN + "subdirectory/"

somewhere in the method ...

def object = Utils.class.getClassLoader().getResource(CAT_1 + "file.xml").text
unmarshaller.unmarshal(new StringSource(object), SomeClass.class).value
1 Answers

Why path on server throw NullPonterException?

Utils.class.getClassLoader().getResource(CAT_1 + "file.xml").text will throw a NullPointerException if CAT_1 + "file.xml" can't be loaded because getResource is going to return null.

Apparently that resource is not available at the path you are expecting it to be available at.

Related