Bug - Fixed NPE when started first time

peter50216

New member
How to reproduce:
Download .jar after version 12705, run it in an empty folder.

The problem is that when there is no folder named "images/", KoLConstants.IMAGE_LOCATION would be a Null pointer in net.sourceforge.kolmafia.request.RelayRequest.ClearImageCache
After manually create a directory called "images/", the problem is solved.

(I know how to read codes on sourceforge, but I don't know how to submit patches :(. It should be a easy fix though.)
 

Veracity

Developer
Staff member
Your instructions are Windows-specific. I'm on a Mac.

I moved the "images" directory to "images.save" and started up KoLmafia. KoLmafia created a new "images" directory for me.

KoLConstants.IMAGE_LOCATION (actually, UtilityConstants.IMAGE_LOCATION) is a File whose path is made by merging ROOT_LOCATION and IMAGE_DIRECTORY. Making a File in that manner has no dependency whatsoever about whether the directory actually exists; you can use File.exists() and File.mkdir() to check for existence and to create the directory if necessary.

The issue is that File.listFiles returns null if the directory does not exist.

So, KoLmafia can start up fine without a "images" directory - and will create it if it wants to read or write a file from it.

I'll just make it create the directory when you start up, if it doesn't exist, just as we do for the "scripts" directory.
 
Top