Uploaded image for project: 'Spigot'
  1. Spigot
  2. SPIGOT-6784

(API) Documenting thread safety of methods and constructors in the Bukkit Api

XMLWordPrintable

    • Icon: New Feature New Feature
    • Resolution: Unresolved
    • Icon: Minor Minor
    • None
    • None
    • This server is running CraftBukkit version 3238-Spigot-6c1c1b2-9217b52 (MC: 1.17.1) (Implementing API version 1.17.1-R0.1-SNAPSHOT)
    • Yes

      Working Repository: Bukkit Api on SyntaxPhoenix

      Everyone is invited to help annotating the whole BukkitApi with the annotations related to this request:

      • FullThreadSafe
      • ContextThreadSafe
      • NonThreadSafe

       

      Explanation:

      FullThreadSafe:
      A method or constructor is FullThreadSafe if that method or constructor can be called on any thread at any time in any context. Meaning there will be no Exception when running this method on multiple thread at the same time on the same object.

      ContextThreadSafe:
      A method or constructor is ContextThreadSafe if the method or constructor uses mutable variables. For example a ArrayList would be ContextThreadSafe. As the owner of the ArrayList can freely modify it and use it while other threads would mostly only be able to read from that List without causing any issues. Most of the time getters for variables of a mutable object can be considered FullThreadSafe however some cannot because of the way they retrieve the corresponding value.

      NonThreadSafe:
      A method or constructor is NonThreadSafe if the method or constructor can only be used on the Main Server Thread. For example stuff like "World.setBlock" would be such an example. 

       

      UPDATE (15.01.2022):

      We finally got time to work on this big project to annotate everything.
      As of now there isn't much annotated, just some mutable objects and that's more or less it.

      The Idea of adding those Annotations is to give developers that use the bukkit api a clear understanding on which method they can use in which context.
      For example there are methods like "Bukkit.createBlockData()" which are in practice completely thread safe however you probably don't know that if you didn't look into the CraftBukkit source.

      Therefore adding such documentation would help developers understand what they can or can not do.

      Also this could lead to consistency along forks and Spigot. As of now some forks have different thread safety for different method compared to Spigot. Maybe by adding those annotations they will either modify those annotations so people that use their fork know as much as the people who use Spigot or they will adjust their code accordingly to the documented thread safety which would make those forks more compatible with Spigot plugins.

       

      Small Info:

      At the beginning this issue was mostly related to the Bukkit.createBlockData method. However just documenting one method makes no sense. Therefore I modified the description and title accordingly and added the concept discussed in the comments as well as the working repository above.

            Unassigned Unassigned
            Lauriichen Lauriichan
            Votes:
            3 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated: