NPE on java tests trying to open a test resource using getClass().getResource()

I started to play with circleci today.

I’ve set one project that is running well on my machine, but at the circleci env it fails with a NPE caused by a java statement trying to get a test resource inside the building jar that will be used to compare.

    a.analyzeResource(new JarResource(new File(getClass()
            .getResource("/testdata/07-optionalimport.jar").getPath())),
            caps, reqs);

the test

the job

Am I missing something ?

Which of your methods resolves unexpectedly to null? At a minimum, you should trap that and output a sensible error, rather than letting it get to an NPE.

my bet is that the NPE is occurring after this method return null:

getClass()
            .getResource("/testdata/07-optionalimport.jar")

But I have opened this report because to me doesn’t make sense this happen only at this environment…

If you don’t know whether getClass() or getResource() is returning null, I’d say the first step is to find out :smiley_cat:. The defensive programming I suggested earlier would be ideal.

Well, embarrassingly, after many many hours, I found where the issue was… :slight_smile:

The culprit was a copied .gitignore file that contained this:

# Package Files #
 target
 *.jar
 *.txt

Eclipse IDE adds a small interrogation icon on the uncommited files, a small repo icon to the committed ones and just remove the icon from the ignored ones. I just didn’t pay attention to those ignored ones.

So, I changed that file to:

# Package Files #
target/*.jar
target/*.txt 

and the mysterious unit tests errors have gone.

thank all for the time…

1 Like

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.