Bug - Fixed NPE in batch_close

xKiv

Active member
Got this:
Code:
Unexpected error, debug log printed.
class java.lang.NullPointerException: null
java.lang.NullPointerException
        at net.sourceforge.kolmafia.textui.RuntimeLibrary.batch_close(RuntimeLibrary.java:1721)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:606)
        at net.sourceforge.kolmafia.textui.parsetree.LibraryFunction.execute(LibraryFunction.java:106)
        at net.sourceforge.kolmafia.textui.parsetree.FunctionCall.execute(FunctionCall.java:154)
        at net.sourceforge.kolmafia.textui.parsetree.BasicScope.execute(BasicScope.java:435)
        at net.sourceforge.kolmafia.textui.parsetree.UserDefinedFunction.execute(UserDefinedFunction.java:153)
        at net.sourceforge.kolmafia.textui.Interpreter.executeScope(Interpreter.java:396)
        at net.sourceforge.kolmafia.textui.Interpreter.execute(Interpreter.java:320)
        at net.sourceforge.kolmafia.textui.Interpreter.execute(Interpreter.java:313)
        at net.sourceforge.kolmafia.textui.command.CallScriptCommand.call(CallScriptCommand.java:256)
        at net.sourceforge.kolmafia.KoLmafiaCLI.doExecuteCommand(KoLmafiaCLI.java:605)
        at net.sourceforge.kolmafia.KoLmafiaCLI.executeCommand(KoLmafiaCLI.java:548)
        at net.sourceforge.kolmafia.KoLmafiaCLI.executeLine(KoLmafiaCLI.java:449)
        at net.sourceforge.kolmafia.KoLmafiaCLI.executeLine(KoLmafiaCLI.java:317)
        at net.sourceforge.kolmafia.swingui.CommandDisplayFrame$CommandQueueHandler.handleQueue(CommandDisplayFrame.java:190)
        at net.sourceforge.kolmafia.swingui.CommandDisplayFrame$CommandQueueHandler.run(CommandDisplayFrame.java:164)

I was running my daily "morning" script, which includes several batched autosales, mallsales, and others. Several of those completed successfully, but then I got a batch of just "autosell 2 marzipan skull" (before that was some smashing, and a batch of DCing 1 stuffed meat and 1 stuffed frozen fairy gravy).

Now any batch operation fails during batch_close (presumable because the broken batch never closed, so it's still there).
I see that interpreter.batched is {sell={null=2 ¶1163}}, which makes the NPE obvious (the null becomes prefix, and the prefix.equals throws). But how did that null get there?

Hmm ... RuntimeLibrary:1619 (in batchCommand(interpreter, cmd, params), cmd is "sell", params was "2 ¶1163"):
Code:
		RuntimeLibrary.batchCommand( interpreter, cmd, null, params );

That null is passed (and used) as prefix ...
 

Veracity

Developer
Staff member
Code:
		String key = prefix == null ? "" : prefix;
		StringBuilder buf = prefixMap.get( prefix );
		if ( buf == null )
		{
			buf = new StringBuilder( params );
			prefixMap.put( prefix, buf );
		}
Notice how I carefully calculate "key" - and then go and use "prefix".
 
Top