Solved ArrayOutOfBounds even though it shouldn't???

Discussion in 'Spigot Plugin Development' started by ondrej008, Jun 2, 2017.

Thread Status:
Not open for further replies.
  1. Hello,
    i have no fucking idea what the fuck is wrong. ZERO idea.
    I'll show you what I mean:
    Code:
    Code (Text):
    l.info(size.toString());
                                l.info("X" + x + "Y" + y + "Z" + z);
                                l.info(data.length + " " + data[1].length + " " + data[0][1].length);
    final BaseBlock block = data[this.x][this.y][this.z];
    Produces (w/ exception):
    Code (Text):
    [15:03:13 INFO]: (36.0, 18.0, 38.0) // size.toString();
    [15:03:13 INFO]: X0Y0Z38 // Z is 38, should be fine.
    [15:03:13 INFO]: 36 18 38 // the length of all the arrays in data
    [15:03:13 WARN]: [Hacker] Task #156 for DogWars v1.0 generated an exception
    java.lang.ArrayIndexOutOfBoundsException: 38 // wth????
            at ondrej008.dogwars.Main$2.run(Main.java:198) ~[?:?]
            at org.bukkit.craftbukkit.v1_8_R3.scheduler.CraftTask.run(CraftTask.java:71) ~[spigot-1.8.8.jar:git-Spigot-5f38d38-18fbb24]
            at org.bukkit.craftbukkit.v1_8_R3.scheduler.CraftScheduler.mainThreadHeartbeat(CraftScheduler.java:350) [spigot-1.8.8.jar:git-Spigot-5f38d38-18fbb24]
            at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:723) [spigot-1.8.8.jar:git-Spigot-5f38d38-18fbb24]
            at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:374) [spigot-1.8.8.jar:git-Spigot-5f38d38-18fbb24]
            at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:654) [spigot-1.8.8.jar:git-Spigot-5f38d38-18fbb24]
            at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:557) [spigot-1.8.8.jar:git-Spigot-5f38d38-18fbb24]
            at java.lang.Thread.run(Unknown Source) [?:1.8.0_111]
    The code isn't that necessary to show,
    but data is a BaseBlock[][][] from WE.
     
    #1 ondrej008, Jun 2, 2017
    Last edited: Jun 2, 2017
  2. pls halp, i don't understand!!! the array has CLEARLY 38 places and I requiest 38 and it makes an exception!
     
  3. Mas

    Mas

    EDIT: Misunderstood
     
  4. CuboidClipboard cc = SchematicFormat.MCEDIT.load(file); Vector size = cc.getSize();
    setting the data[0][1] to data[0][2] doesn't change anything.
     
  5. Mas

    Mas

    I believe the issue is that the value "this.z" is exceeding 37.
    Try loggin this.x, this.y and this.z to see.
     
  6. Arrays start at 0 and go up to the length minus 1. So, an array with 38 elements would start at 0 and end at 37.
     
    • Like Like x 1
  7. Are you blind?
    Changing it to this.z has no change, again.
     
  8. Oh, okay, how would I fix this then?
    Here is most of the code:
    y,z start at 0.
    Code (Text):
    for(; this.y <= size.getBlockY(); this.y++) {
                            for(; this.z <= size.getBlockZ(); this.z++) {
                                l.info(size.toString());
                                l.info("X" + this.x + "Y" + this.y + "Z" + this.z);
                                l.info(data.length + " " + data[1].length + " " + data[0][2].length);
                                final BaseBlock block = data[x][y][z];
                             
                            }
                         
                        }
     
  9. This is the most trash code I have ever seen. Write something better that doesn't give these kind of exceptions.
     
    • Funny Funny x 1
  10. What do you mean trash code? It's almost 100% from WorldEdit... only with like 3 lines added...
    So you're saying that WE has trash code?
    What kinds of exceptions? You mean the ArrayOutOfBounds?
     
    • Funny Funny x 1
  11. Just change your code so that this.z isn't ever higher than 37
     
Thread Status:
Not open for further replies.