Bug - Fixed java.util.NoSuchElementException

Bale

Minion
The error looks like this:

Code:
> registry

Unexpected error, debug log printed.
Script execution aborted (java.util.NoSuchElementException): (zlib.ash, line 703)



Code:
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
         KoLmafia v16.8 r15630, Windows XP, Java 1.7.0_55
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
 Please note: do not post this log in the KoLmafia thread of KoL's
 Gameplay-Discussion forum. If you would like the KoLmafia dev team
 to look at it, please write a bug report at kolmafia.us. Include
 specific information about what you were doing when you made this
 and include this log as an attachment.
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
 Timestamp: Mon Mar 23 02:03:34 EDT 2015
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


Unexpected error, debug log printed.
class java.util.NoSuchElementException: null
java.util.NoSuchElementException
	at java.util.LinkedList.getFirst(Unknown Source)
	at net.sourceforge.kolmafia.session.ResultProcessor.processItem(ResultProcessor.java:468)
	at net.sourceforge.kolmafia.session.ResultProcessor.processNextResult(ResultProcessor.java:439)
	at net.sourceforge.kolmafia.session.ResultProcessor.processNormalResults(ResultProcessor.java:361)
	at net.sourceforge.kolmafia.session.ResultProcessor.processResults(ResultProcessor.java:331)
	at net.sourceforge.kolmafia.textui.RuntimeLibrary.extract_meat(RuntimeLibrary.java:5217)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	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.Assignment.execute(Assignment.java:103)
	at net.sourceforge.kolmafia.textui.parsetree.BasicScope.execute(BasicScope.java:435)
	at net.sourceforge.kolmafia.textui.parsetree.Conditional.execute(Conditional.java:96)
	at net.sourceforge.kolmafia.textui.parsetree.If.execute(If.java:68)
	at net.sourceforge.kolmafia.textui.parsetree.BasicScope.execute(BasicScope.java:435)
	at net.sourceforge.kolmafia.textui.parsetree.Loop.execute(Loop.java:59)
	at net.sourceforge.kolmafia.textui.parsetree.WhileLoop.execute(WhileLoop.java:100)
	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.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.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.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:401)
	at net.sourceforge.kolmafia.textui.Interpreter.execute(Interpreter.java:325)
	at net.sourceforge.kolmafia.textui.Interpreter.execute(Interpreter.java:318)
	at net.sourceforge.kolmafia.textui.command.CallScriptCommand.call(CallScriptCommand.java:256)
	at net.sourceforge.kolmafia.KoLmafiaCLI.doExecuteCommand(KoLmafiaCLI.java:606)
	at net.sourceforge.kolmafia.KoLmafiaCLI.executeCommand(KoLmafiaCLI.java:549)
	at net.sourceforge.kolmafia.KoLmafiaCLI.executeLine(KoLmafiaCLI.java:450)
	at net.sourceforge.kolmafia.KoLmafiaCLI.executeLine(KoLmafiaCLI.java:318)
	at net.sourceforge.kolmafia.swingui.CommandDisplayFrame$CommandQueueHandler.handleQueue(CommandDisplayFrame.java:187)
	at net.sourceforge.kolmafia.swingui.CommandDisplayFrame$CommandQueueHandler.run(CommandDisplayFrame.java:163)

The exact line in zlib is

Code:
         mail[n].meat = extract_meat(mbits.group(2));

According to a debugging print statement, mbits.group(2) is
Code:
<table class=\"item\" style=\"float: none\" rel=\"id=7731&s=0&q=0&d=0&g=0&t=1&n=1&m=0&p=0&u=u&ou=decrypt\"><tr><td><img src=\"http:\/\/images.kingdomofloathing.com\/itemimages\/transmission.gif\" alt=\"transmission from planet Xi\" title=\"transmission from planet Xi\" class=hand onClick='descitem(638258454)'><\/td><td valign=center class=effect>You acquire an item: <b>transmission from planet Xi<\/b><\/td><\/tr><\/table><\/center>"

When I run that string through extract_meat() it works fine, but only outside of the script.
 

Bale

Minion
It works now.

Can you tell me why it failed even though it has worked many times in the past?
 

Veracity

Developer
Staff member
I whacked how we process results.

Recently, Darzil made result processing do everything via item ID or effect descid. In order to do that, he had to process the response text before we stripped all the html from it. Therefore, he processed those results first and pulled them out of the page text, which was then processed to get all the other results.

I liked the accuracy of doing it via ids rather than names, but I did not like the way all those results got logged before everything else, rather than inline with everything else on the page. So, if you ate 5 items at once with Milk active, you'd see 5 "You lose some of an effect: Got Milk (-3)" and THEN the adventure & stat gains for each food item.

So, I adjusted it such that it located all the results with ids and built a list of items and a list of effects, while leaving the results in the response text. Then, when we processed the text, each time we found an item or effect, if it matched the first saved result from the appropriate list, we'd pop off that result and process it, rather than doing the old-style parsing.

I had a bug, however: you could have an empty list of items but still have an item on the page; pickpocketed items do not have relstrings, for example, and do not get preprocessed by item id. And I made a bad assumption about Java's LinkedList.getFirst() - I assumed that if the list was empty, it'd return null. Had I actually read the documentation, I'd have seen that instead, it throws an exception. So, I fixed that.

I saw that you were extracting meat, or something, from a page, but I didn't actually pay attention to that; the stack trace showed the exception being thrown by the new code I'd just added. So I found all three of the places I called getFirst() and made them behave correctly.

tldr; it worked many times in the past until I changed the code and busted it. :)
 

Bale

Minion
I figured it was probably because of a refactoring, but wasn't sure.

Thanks for explaining, as always.
 
Top