Bug - Waiting for Info r17703 debug log - Unable to normalize type 'familiar'

Magus_Prime

Well-known member
Started a combat and got the following:

Code:
[499] The Haunted Wine Cellar
Encounter: mad wino WITH BACON!!!
Round 0: Arbos wins initiative!
WHAM: Running SmartStasis
Round 1: Arbos executes a macro!
Round 1: Arbos casts CURSE OF WEAKSAUCE!
Round 2: mad wino drops 6 attack power.
Round 2: mad wino drops 8 defense.
Round 2: Arbos casts EXTRACT!
You acquire an item: Source essence (2)
Round 3: mad wino drops 7 attack power.
Round 3: mad wino drops 9 defense.
Round 3: You lose 28 hit points
Round 3: Arbos uses the Time-Spinner!
Round 4: mad wino drops 8 attack power.
Round 4: mad wino drops 8 defense.
Round 4: mad wino drops 7 attack power.
Round 4: mad wino drops 8 defense.
Round 4: Arbos executes a macro!
Round 4: Arbos casts ENTANGLING NOODLES!
Round 5: mad wino drops 10 attack power.
Round 5: mad wino drops 9 defense.
Round 5: mad wino drops 6 attack power.
Round 5: mad wino drops 7 defense.
Validating adventure sequence...
Condition added: bottle of Chateau de Vinegar

WHAM: Starting evaluation and performing of attack
Unable to normalize type 'familiar'.
Unexpected error, debug log printed.
Script execution aborted (Index: 5, Size: 6): (BatBrain.ash, line 1972)
You're on your own, partner.
You're on your own, partner.
Click here to continue in the relay browser.

Here's the debug log: View attachment DEBUG_20170118.txt
 

Veracity

Developer
Staff member
Code:
java.lang.IndexOutOfBoundsException: Index: 5, Size: 6
	at java.util.ArrayList.rangeCheck(Unknown Source)
	at java.util.ArrayList.remove(Unknown Source)
	at net.sourceforge.kolmafia.textui.parsetree.ForEachLoop.executeSlice(ForEachLoop.java:201)
	at net.sourceforge.kolmafia.textui.parsetree.ForEachLoop.execute(ForEachLoop.java:107)
...
Um. The list has size = 6 and therefore index 0 - 5, and index = 5 yields an "IndexOutOfBoundsException"?

Yer Java's broke, son.
 

Veracity

Developer
Staff member
His debug log says this:

KoLmafia v17.6 r17703, Windows 10, Java 1.8.0_111

I'm running 1.8.0_121, by the way, and have seen no problems yet.
 

Magus_Prime

Well-known member
Yer Java's broke, son.

That made me laugh out loud. Thank you!

I was able to continue with both the combat and the rest of the session without problem. The one odd thing I noticed was this bit:

Code:
Round 5: mad wino drops 6 attack power.
Round 5: mad wino drops 7 defense.
Validating adventure sequence...
Condition added: bottle of Chateau de Vinegar

Note the added goal in the middle of a combat round when automating turns. What happened is that:

1. I realized that I hadn't set the goal in the Wine Cellar
2. Went to the Adventure pane and added the goal as active
3. Mafia added the goal mid-round

That was when "something" became unhappy.
 
Last edited:

xKiv

Active member
Code:
java.lang.IndexOutOfBoundsException: Index: 5, Size: 6
	at java.util.ArrayList.rangeCheck(Unknown Source)
	at java.util.ArrayList.remove(Unknown Source)
	at net.sourceforge.kolmafia.textui.parsetree.ForEachLoop.executeSlice(ForEachLoop.java:201)
	at net.sourceforge.kolmafia.textui.parsetree.ForEachLoop.execute(ForEachLoop.java:107)
...
Um. The list has size = 6 and therefore index 0 - 5, and index = 5 yields an "IndexOutOfBoundsException"?

Yer Java's broke, son.

Can that run from multipe threads? ArrayList isn't thredsafe.
Code:
if (index >= size)
 throw new IndexOutOfBoundsException("Index: "+index+", Size: "+size);
can
1) fail the if with index=5, size=4
2) get interruped by another thread (or two), which adds two elements (increasing size to 6)
3) throw IOOBE("Index: 5, Size: 6")
 

Veracity

Developer
Staff member
It is treating an ArrayList as a stack in an instance of an Interpreter. Every time you enter a foreach loop, it pushes three elements on it. It pops them off when you exit the loop.

(The point is to keep track of nested iterators so that you can "remove" an item from any map you are iterating over.)

An Interpreter can only be used in a single thread. There is one made per active script. For Relay scripts, at least, we synchronize on the Interpreter object.

Looking at the other end of his call stack:

Code:
	at net.sourceforge.kolmafia.textui.Interpreter.execute(Interpreter.java:318)
	at net.sourceforge.kolmafia.request.FightRequest.nextRound(FightRequest.java:970)
	at net.sourceforge.kolmafia.request.FightRequest.runOnce(FightRequest.java:1842)
	at net.sourceforge.kolmafia.request.FightRequest.run(FightRequest.java:1874)
	at net.sourceforge.kolmafia.webui.RelayAutoCombatThread.run(RelayAutoCombatThread.java:76)
He's in a consult script. FightRequest does not synchronize on consult scripts. You are not supposed to be handling the same combat in more than one thread. I've never really studied the RelayAutoCombatThread.

Looking at the code, the Relay Agent wakes it up when you hit the "custom" button in the Relay Browser.

So... if you are executing a fight in the Relay Browser and then start adventuring in the GUI, that would redirect to fight.php, which could end up calling the same consult script.

He said this:

Code:
Round 5: mad wino drops 6 attack power.
Round 5: mad wino drops 7 defense.
Validating adventure sequence...
Condition added: bottle of Chateau de Vinegar
He was trying to set the goal, but, notice the "Validating adventure sequence". Apparently it did try to automate.

Both the RelayAutoCombatScript and GUI automation handle fights in FightRequest.INSTANCE. Presumably, both could synchronize on that, somehow. But that's actually a little late: the automation is happening in the Relay Browser when the GUI submits a request to adventure.php, which is directed to fight.php, hence this clash.

I have, very rarely, seen what appear to be multiple threads trying to automate multiple adventures at once. The GUI greys out when it is adventuring, but I imagine you could adventure via a script and then try to adventure via the GUI, or vice versa. And this, with the Relay Browser, is a way to automate a single fight, at least.

This is going to require some careful thought.
 

fronobulax

Developer
Staff member
Thank you for the analysis. I have seen array list out of bounds errors occasionally, but since the stack trace pointed to an interpreter I tended to dismiss them as Ash programmer errors. I'll try to pay better attention next time.
 

Darzil

Developer
I have, very rarely, seen what appear to be multiple threads trying to automate multiple adventures at once. The GUI greys out when it is adventuring, but I imagine you could adventure via a script and then try to adventure via the GUI, or vice versa. And this, with the Relay Browser, is a way to automate a single fight, at least.

This is going to require some careful thought.

I am HOPING that r18802 stops this by delaying one if the other is in progress.
 
Top