Experimental: Attempted fix for rare ArrayIndexOutOfBoundsException

This might fix #1095 It will at least prevent crashes in those weird situations.