Bug - Fixed Unknown because I don't code?

Code:
Unexpected error, debug log printed.
class java.lang.ArrayIndexOutOfBoundsException: -1
java.lang.ArrayIndexOutOfBoundsException: -1
	at java.util.ArrayList.elementData(Unknown Source)
	at java.util.ArrayList.get(Unknown Source)
	at java.util.Collections$SynchronizedList.get(Unknown Source)
	at net.sourceforge.kolmafia.swingui.panel.DailyDeedsPanel$HatterDaily.getEffectHat(DailyDeedsPanel.java:3553)
	at net.sourceforge.kolmafia.swingui.panel.DailyDeedsPanel$HatterDaily$HatterComboListener.actionPerformed(DailyDeedsPanel.java:3578)
	at javax.swing.JComboBox.fireActionEvent(Unknown Source)
	at javax.swing.JComboBox.contentsChanged(Unknown Source)
	at javax.swing.AbstractListModel.fireContentsChanged(Unknown Source)
	at javax.swing.DefaultComboBoxModel.setSelectedItem(Unknown Source)
	at javax.swing.DefaultComboBoxModel.addElement(Unknown Source)
	at javax.swing.JComboBox.addItem(Unknown Source)
	at net.sourceforge.kolmafia.swingui.widget.DisabledItemsComboBox.addItem(DisabledItemsComboBox.java:65)
	at net.sourceforge.kolmafia.swingui.panel.DailyDeedsPanel$HatterDaily.update(DailyDeedsPanel.java:3524)
	at net.sourceforge.kolmafia.listener.ListenerRegistry.fireListeners(ListenerRegistry.java:255)
	at net.sourceforge.kolmafia.listener.ListenerRegistry.fireAllListeners(ListenerRegistry.java:216)
	at net.sourceforge.kolmafia.listener.PreferenceListenerRegistry.fireAllPreferencesChanged(PreferenceListenerRegistry.java:59)
	at net.sourceforge.kolmafia.preferences.Preferences.reset(Preferences.java:142)
	at net.sourceforge.kolmafia.KoLmafia.timein(KoLmafia.java:611)
	at net.sourceforge.kolmafia.request.LoginRequest.processLoginRequest(LoginRequest.java:449)
	at net.sourceforge.kolmafia.request.GenericRequest.handleServerRedirect(GenericRequest.java:1984)
	at net.sourceforge.kolmafia.request.GenericRequest.retrieveServerReply(GenericRequest.java:1863)
	at net.sourceforge.kolmafia.request.GenericRequest.execute(GenericRequest.java:1516)
	at net.sourceforge.kolmafia.request.GenericRequest.run(GenericRequest.java:1410)
	at net.sourceforge.kolmafia.request.LoginRequest.run(LoginRequest.java:279)
	at net.sourceforge.kolmafia.RequestThread.postRequest(RequestThread.java:287)
	at net.sourceforge.kolmafia.RequestThread.postRequest(RequestThread.java:250)
	at net.sourceforge.kolmafia.request.LoginRequest.executeTimeInRequest(LoginRequest.java:362)
	at net.sourceforge.kolmafia.request.GenericRequest.handleServerRedirect(GenericRequest.java:2048)
	at net.sourceforge.kolmafia.request.GenericRequest.retrieveServerReply(GenericRequest.java:1863)
	at net.sourceforge.kolmafia.request.GenericRequest.execute(GenericRequest.java:1516)
	at net.sourceforge.kolmafia.request.GenericRequest.run(GenericRequest.java:1410)
	at net.sourceforge.kolmafia.request.RelayRequest.run(RelayRequest.java:2792)
	at net.sourceforge.kolmafia.RequestThread.postRequest(RequestThread.java:287)
	at net.sourceforge.kolmafia.RequestThread.postRequest(RequestThread.java:250)
	at net.sourceforge.kolmafia.webui.RelayAgent.readServerResponse(RelayAgent.java:550)
	at net.sourceforge.kolmafia.webui.RelayAgent.performRelay(RelayAgent.java:155)
	at net.sourceforge.kolmafia.webui.RelayAgent.run(RelayAgent.java:128)
 

Bale

Minion
What were you doing when that happened? Copy/paste from your session log if you can, please.
 

Veracity

Developer
Staff member
He clicked something in the Relay Browser.
He had timed out, so KoL redirected him to the login page.
KoLmafia detected that and timed him in again.
As part of that process, apparently we reset preferences, which resets everything that depends on a preference.
In particular, the "hatter" daily deed, which took an ABE - an Array Index Out Of Bounds exception.

I invite you to examine the following code in DailyDeedsPanel:

Code:
		private class HatterComboListener
			implements ActionListener
		{
			public void actionPerformed( final ActionEvent e )
			{
				DisabledItemsComboBox cb = (DisabledItemsComboBox) e.getSource();

				if ( cb.getItemCount() == 0 )
				{
					return;
				}

				if ( cb.getSelectedIndex() == 0 )
				{
					setComboTarget( btn, "" );
				}
				else
				{
					String Choice = cb.getSelectedItem().toString();

					if ( Choice != null )
					{
						setComboTarget( btn, "hatter " + HatterDaily.getEffectHat( cb.getSelectedIndex() ) );
					}
				}
			}
		}
This expression - cb.getSelectedIndex() - is returning -1. Here is what the documentation of JComboBox.getSelectedIndex says:

Returns the first item in the list that matches the given item. The result is not always defined if the JComboBox allows selected items that are not in the list. Returns -1 if there is no selected item or if the user specified an item which is not in the list.
This combo box is actually a DisabledItemComboBox.

I couldn't say why it is getting an index of -1, but that method I included seems to think that index 0 means "nothing selected" - which is incorrect.
 

Veracity

Developer
Staff member
P.S. There are quite a few other similar methods in that file. DemonComboBox, ShowerComboBox, etc.
 

Veracity

Developer
Staff member
that method I included seems to think that index 0 means "nothing selected" - which is incorrect.
Well, index 0 will be "Available Hatter Buffs:" or "April Shower" or whatever - so, it is effectively "nothing selected".

I expect that if the index is ever -1, it should be treated like index 0...
 
Top