MegaMek / mekhq

MekHQ is a java helper program for the MegaMek game that allows users to load a list of entities from an XML file, perform repairs and customizations, and then save the new entities to another XML file that can be loaded into MegaMek.
http://megamek.org
131 stars 170 forks source link

BA Project Breaking loading in MekHQ (concurrent.ExecutionException: java.lang.ArrayIndexOutOfBoundsException) #3412

Open HammerGS opened 2 years ago

HammerGS commented 2 years ago

I've completed the BA project and all names and unit files have been updated to match the new MUL squad tags (Sqd4,5,6). All unit roles, quirks, and the name_change.txt file have been updated. I've moved the unit files over to the MekHQ file in IDEA, refreshed everything and MekHQ crashes on the attached test campaign file.

Environment

What version of MekHQ does your issue apply to? 49.9-Dev in the Repo as off this date What operating system are you using? Windows What java version are you using? 11

11:42:20,715 ERROR [mekhq.gui.dialog.DataLoadingDialog.Task] {AWT-EventQueue-0}
mekhq.gui.dialog.DataLoadingDialog$Task.done(DataLoadingDialog.java:358) - 
java.util.concurrent.ExecutionException: java.lang.ArrayIndexOutOfBoundsException: Index 1 out of bounds for length 1
    at java.base/java.util.concurrent.FutureTask.report(FutureTask.java:122)
    at java.base/java.util.concurrent.FutureTask.get(FutureTask.java:191)
    at java.desktop/javax.swing.SwingWorker.get(SwingWorker.java:613)
    at mekhq.gui.dialog.DataLoadingDialog$Task.done(DataLoadingDialog.java:354)
    at java.desktop/javax.swing.SwingWorker$5.run(SwingWorker.java:750)
    at java.desktop/javax.swing.SwingWorker$DoSubmitAccumulativeRunnable.run(SwingWorker.java:847)
    at java.desktop/sun.swing.AccumulativeRunnable.run(AccumulativeRunnable.java:112)
    at java.desktop/javax.swing.SwingWorker$DoSubmitAccumulativeRunnable.actionPerformed(SwingWorker.java:857)
    at java.desktop/javax.swing.Timer.fireActionPerformed(Timer.java:317)
    at java.desktop/javax.swing.Timer$DoPostEvent.run(Timer.java:249)
    at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:313)
    at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:770)
    at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:721)
    at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:715)
    at java.base/java.security.AccessController.doPrivileged(Native Method)
    at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
    at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:740)
    at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
    at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
    at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
    at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
    at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
    at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
Caused by: java.lang.ArrayIndexOutOfBoundsException: Index 1 out of bounds for length 1
    at mekhq.campaign.unit.cleanup.BattleArmorEquipmentUnscrambler.assignTroopersAndEquipmentNums(BattleArmorEquipmentUnscrambler.java:87)
    at mekhq.campaign.unit.cleanup.BattleArmorEquipmentUnscrambler.unscramble(BattleArmorEquipmentUnscrambler.java:45)
    at mekhq.campaign.io.CampaignXmlParser.lambda$parse$0(CampaignXmlParser.java:403)
    at mekhq.campaign.Hangar.lambda$forEachUnit$0(Hangar.java:117)
    at java.base/java.util.LinkedHashMap.forEach(LinkedHashMap.java:684)
    at mekhq.campaign.Hangar.forEachUnit(Hangar.java:117)
    at mekhq.campaign.io.CampaignXmlParser.parse(CampaignXmlParser.java:374)
    at mekhq.campaign.CampaignFactory.createCampaign(CampaignFactory.java:83)
    at mekhq.gui.dialog.DataLoadingDialog$Task.doInBackground(DataLoadingDialog.java:329)
    at mekhq.gui.dialog.DataLoadingDialog$Task.doInBackground(DataLoadingDialog.java:190)
    at java.desktop/javax.swing.SwingWorker$1.call(SwingWorker.java:304)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
    at java.desktop/javax.swing.SwingWorker.run(SwingWorker.java:343)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
    at java.base/java.lang.Thread.run(Thread.java:829)

All unit files, name_change.txt and quirks are current in the MegaMek repo.

BA Test31510101.cpnx.gz

HammerGS commented 2 years ago

Logs from the nightly build. Same error. Looked specifically into unit files here and don't see anything odd.

18:43:26,330 WARN  [mekhq.campaign.parts.equipment.AmmoBin] {SwingWorker-pool-2-thread-1}
mekhq.campaign.parts.equipment.AmmoBin.getMounted(AmmoBin.java:296) - Missing valid equipment for BA SRM 1 Ammo Bin to manage ammo on unit Constable Pacification Suit [ECM] (Sqd5) #2

18:43:26,336 WARN  [mekhq.campaign.parts.equipment.AmmoBin] {SwingWorker-pool-2-thread-1}
mekhq.campaign.parts.equipment.AmmoBin.getMounted(AmmoBin.java:296) - Missing valid equipment for BA SRM 4 Ammo Bin to manage ammo on unit Grenadier II Battle Armor A(Sqd4)

18:43:26,336 WARN  [mekhq.campaign.parts.equipment.AmmoBin] {SwingWorker-pool-2-thread-1}
mekhq.campaign.parts.equipment.AmmoBin.getMounted(AmmoBin.java:296) - Missing valid equipment for BA SRM 4 Ammo Bin to manage ammo on unit Grenadier II Battle Armor A(Sqd4)

legacy.log megamek.log megameklab.log mekhq.log

neoancient commented 2 years ago

The Nighthawk PA(L) Mk. XXX (Bounty Hunter) went from 4 suits to 1 and the Water Elemental Mining Suit went from 5 suits to 4. If there are any that increased in size that won't cause a problem. It's just the decrease. It's trying to assign parts from the missing trooper(s) to a location that doesn't exist.

HammerGS commented 2 years ago

Hmm....any good code work arounds as those suits got revised down? Or best to add in new units and rematch the names?

neoancient commented 2 years ago

I see three options, though others may see more:

  1. Range checks where the parts are being assigned. It may be ok to ignore the extra parts, or something may need to be done with them. I didn't look far enough into it.
  2. Remove those entries from the name changes file. I doubt they affect very many campaigns and they may be best handled the old way.
  3. Add additional unit files to match the ones that were removed.

Of the three I think the first is the best overall, but more involved and I would leave it to someone who's worked with MekHQ more recently than I have to make that call. The second is the easiest and may be sufficient for real-world use. The third is presented as a possibility but I don't recommend it.

HammerGS commented 2 years ago

I've done fix 2 as part of this - https://github.com/MegaMek/megamek/issues/3819

But leaving this open till a coder can decide if option 1 should be done or not.