Tutorial Guide to debug your own plugins

Discussion in 'Resources' started by mcdorli, Nov 20, 2015.

Thread Status:
Not open for further replies.
  1. Offline


    A lot of people come here to the forums, asking for help, and wait at least an hour to get the correct answer, when they could just use some simple techniques and get the answer instantly.

    0.: (You shouldn't even be here if this is your problem) Error message in IDE:

    Doesn't matter what IDE you use, in almost every IDE there is a function, wich tells you, what you did wrong. You can hover over them with you mouse, and it will show you the problem.

    The first is IntelliJ, the second is Eclipse.

    1.: The stack-trace (java error):

    The first thing you should check is if there are any errors in the log. It is easy to troubleshoot your error logs (more in this guide: http://bukkit.org/threads/how-to-re...ubleshoot-your-own-plugins-by-yourself.32457/). This is the best way against exceptions, like:

    - NullPointerException (Something is null, but it shouldn't be)
    - IllegalArgumentException (The argument you passed is not compatible with what it wants)
    - ArrayIndexOutOfBoundException (You tried to reference something outside of the array's bounds)

    2.: Debug messages (typos):

    If you didn't got too far with the first method, then there is no real java-error in your code. Maybe you messed up something with your if-s (for instance you used != instead of ==). In this case you can put a lot of System.out-s in your code, to see, where it stops.

    int x = 3;
    int y = 2;
    int z = 5;
    if (x == 3) {
        getLogger().info("x is 3");
        if (y != 2) {
            getLogger().info("y is 2");    //This won't print out "y is 2", because the if only fires, if y isn't 2.
            if (z == 5) {
                getLogger().info("z is 5");
                player.getInventory().addItem(new ItemStack(material.DIAMOND, 1));
    3.: (Don't laugh) the rubber duck method (logic error):

    Funnily, this technique is used by programmers in big companies, and it works. You stick a rubber duck near your screen, and try to explain him/her the logic behind the program. If it isn't an error, nor you messed up, then maybe it is a logic bug.

    More about this: http://www.rubberduckdebugging.com/

    4.: Referring to the javadocs (order error):

    Programmers aren't like in the movies, they doesn't know everything. They most viewed page is probably stackoverflow.com, or a reference page. There are no errors, no typos, no logic error, then you did something in the wrong order, or forgot to do something.

    The javadocs:

    Bukkit 1.7: http://jd.bukkit.org/
    Spigot 1.8: https://hub.spigotmc.org/javadocs/bukkit/

    5.: (This is not a real debugging method) Rewriting the code (nothing works):

    If you can't find any errors, bugs, typos, or anything that could cause the problem in your code, then there is no other chance, you need to rewrite it. If the error still occurs after this is done, then you didn't checked everything with the above methods.
    Last edited: Nov 20, 2015
    Chloe-chan likes this.
  2. Offline

    Mrs. bwfctower

    I disagree with this. There's always a reason something isn't working. Rewriting it will likely not fix your issue at hand unless you completely change how you're doing whatever you're doing, which you shouldn't have to do if you're actually programming (as opposed to coding; see signature).
  3. Offline


    That is a "if nothing works" option. It is a really big problem, if it is the answer for the errors.
  4. Offline

    Mrs. bwfctower

    It's not a way to debug, so I don't think it belongs in a thread about how to debug. Anyways, the rest of the post is nice, good job
  5. Offline


    I mentioned it just for you. Happy?
    Mrs. bwfctower likes this.
  6. Offline


    +1 for rubber duck debugging!

    In fact, the process of coding is similar to that debugging. You are translating the solution in your mind into a dumb machine.
    teej107 likes this.
Thread Status:
Not open for further replies.

Share This Page