Discussion in 'Plugin Development' started by peteyandpika, Feb 17, 2013.
i just want to know how they form/what causes them and how you can fix them
Through careful planning and precision placement.
They usually form due to overlooking something when coding a feature. For example, not including a check if a number is greater than a max or something. To fix bugs, you first narrow it down through debugging. (Basically just step through the code, maybe by logging to the console), then finding exactly where it goes wrong. Once you know what method/line causes it. You work out why that method/line causes it. Then you work out how to fix it. Once you've done all that, you test it and hope its fixed. If not, double check you fixed it, and if you think you have, step through the code again.
In my experience with Bukkit plugins, the most errors appear in places where Bukkit code collides with your code. Most often, this is as simple as forgetting to check the values returned by Bukkit methods for validity. As an example, if you attempt to get a player's vehicle (minecart, pig, boat, etc) without checking if a player is actually seated in a vehicle, you might get a NullPointerException.
Outside of Bukkit, errors most often begin in ambiguous code. Multiple loops, huge nested functions, and so on.
Some errors originate due to not understanding how Java works, which is totally fine - we all learn. For example, if you attempt to remove an item from and ArrayList while iterating through the same ArrayList, you will get a ConcurrentModificationException.
Separate names with a comma.