The Spice of Life

The Spice of Life

16M Downloads

IllegalArgumentException when filling lunchbox

andrewminer opened this issue ยท 4 comments

commented

STEPS

Using Spice of Life 1.3 on Minecraft 1.7.10 with Minecraft Forge 10.13.4.1566:

  1. Fill a chest with food from vanilla Minecraft, Pam's Harvestcraft, and Forestry (e.g., honey capsules, etc.)
  2. Shift+right click your empty lunch box to open it
  3. Right click the chest with the open, empty lunch box.

EXPECTED

The lunchbox gets filled with food.

ACTUAL

In very rare circumstances (which I can't reproduce readily), the following exception is raised which crashes the entire server:

java.lang.IllegalArgumentException: Comparison method violates its general contract!                                  
    at java.util.TimSort.mergeLo(TimSort.java:777) ~[?:1.8.0_66]                                                      
    at java.util.TimSort.mergeAt(TimSort.java:514) ~[?:1.8.0_66]                                                      
    at java.util.TimSort.mergeCollapse(TimSort.java:441) ~[?:1.8.0_66]                                                
    at java.util.TimSort.sort(TimSort.java:245) ~[?:1.8.0_66]                                                         
    at java.util.Arrays.sort(Arrays.java:1512) ~[?:1.8.0_66]                                                          
    at java.util.ArrayList.sort(ArrayList.java:1454) ~[?:1.8.0_66]                                                    
    at java.util.Collections.sort(Collections.java:175) ~[?:1.8.0_66]                                                 
    at squeek.spiceoflife.helpers.MealPrioritizationHelper.findBestFoodsForPlayerAccountingForVariety(MealPrioritizationHelper.java:130) ~[MealPrioritizationHelper.class:?]
    at squeek.spiceoflife.items.ItemFoodContainer.tryPullFoodFrom(ItemFoodContainer.java:145) ~[ItemFoodContainer.class:?]
    at squeek.spiceoflife.items.ItemFoodContainer.onItemUseFirst(ItemFoodContainer.java:276) ~[ItemFoodContainer.class:?]
    at net.minecraft.server.management.ItemInWorldManager.func_73078_a(ItemInWorldManager.java:360) ~[mx.class:?]           
    at net.minecraft.network.NetHandlerPlayServer.func_147346_a(NetHandlerPlayServer.java:556) ~[nh.class:?]          
    at net.minecraft.network.play.client.C08PacketPlayerBlockPlacement.func_148833_a(SourceFile:60) ~[jo.class:?]           
    at net.minecraft.network.play.client.C08PacketPlayerBlockPlacement.func_148833_a(SourceFile:9) ~[jo.class:?]            
    at net.minecraft.network.NetworkManager.func_74428_b(NetworkManager.java:212) ~[ej.class:?]                       
    at net.minecraft.network.NetworkSystem.func_151269_c(NetworkSystem.java:165) [nc.class:?]                         
    at net.minecraft.server.MinecraftServer.func_71190_q(MinecraftServer.java:659) [MinecraftServer.class:?]          
    at net.minecraft.server.dedicated.DedicatedServer.func_71190_q(DedicatedServer.java:334) [lt.class:?]             
    at net.minecraft.server.MinecraftServer.func_71217_p(MinecraftServer.java:547) [MinecraftServer.class:?]          
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:427) [MinecraftServer.class:?]                   
    at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:685) [li.class:?]                              

commented

Very strange, thanks for reporting it, I'll try to look into it. If you happen to find a way to consistently reproduce it, that'd help a ton.

commented

Think I might have figured out the cause--when two foods have equal diminishing returns values I made the comparison function return a random result, which is not how comparison functions are meant to work (Java requires that if A > B and B > C then for any A, B and C: A > C).

Long story short: I'm a dummy. Will try to get this fixed soon.

commented

That makes a lot of sense. I've got a double-chest with every slot containing a different food item, and I routinely fill my lunchbox from it. Given how often I use it, It's actually a little surprising this is the first time I've encountered this bug!

commented

Yeah, turns out it's actually pretty rare even when I'm trying to trigger it intentionally in test code. I needed to add 50 or so equally diminished foods to a list and then shuffle + sort it 1000 times to trigger the error consistently. Thanks again for reporting it, will be an easy fix.