Is there any standard annotation for nothrow semantics in Java?

I would like to document the interface method in Java, since it is not allowed to throw exceptions and have some kind of static analysis confirming that implementations of this method capture and handle any exceptions that can be propagated to it. Something along the lines @NoThrow.

For example, I would like to write:

interface SomeServiceProviderInterface {
   @NoThrow
   @NonNull
   SomeResult someComputation();
}

... and they have some guarantee that implementations obey this interface. Is there an annotation and static analysis tool that already does this? If not, does anyone know if this is possible using an annotation handler (can he see if the code includes a try ... catch block?) And / or has any pointers or tips on how to implement this thing? Thanks!

+4
source share

Source: https://habr.com/ru/post/1605652/


All Articles