Package lombok

Class Lombok


  • public class Lombok
    extends java.lang.Object
    Useful utility methods to manipulate lombok-generated code.
    • Constructor Summary

      Constructors 
      Constructor Description
      Lombok()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static <T> T checkNotNull​(T value, java.lang.String message)
      Ensures that the value is not null.
      static <T> T preventNullAnalysis​(T value)
      Returns the parameter directly.
      static java.lang.RuntimeException sneakyThrow​(java.lang.Throwable t)
      Throws any throwable 'sneakily' - you don't need to catch it, nor declare that you throw it onwards.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Lombok

        public Lombok()
    • Method Detail

      • sneakyThrow

        public static java.lang.RuntimeException sneakyThrow​(java.lang.Throwable t)
        Throws any throwable 'sneakily' - you don't need to catch it, nor declare that you throw it onwards. The exception is still thrown - javac will just stop whining about it.

        Example usage:

        public void run() {
             throw sneakyThrow(new IOException("You don't need to catch me!"));
         }

        NB: The exception is not wrapped, ignored, swallowed, or redefined. The JVM actually does not know or care about the concept of a 'checked exception'. All this method does is hide the act of throwing a checked exception from the java compiler.

        Note that this method has a return type of RuntimeException; it is advised you always call this method as argument to the throw statement to avoid compiler errors regarding no return statement and similar problems. This method won't of course return an actual RuntimeException - it never returns, it always throws the provided exception.

        Parameters:
        t - The throwable to throw without requiring you to catch its type.
        Returns:
        A dummy RuntimeException; this method never returns normally, it always throws an exception!
      • preventNullAnalysis

        public static <T> T preventNullAnalysis​(T value)
        Returns the parameter directly. This method can be used to prevent a static analyzer to determine the nullness of the passed parameter.
        Type Parameters:
        T - the type of the parameter.
        Parameters:
        value - the value to return.
        Returns:
        value (this method just returns the parameter).
      • checkNotNull

        public static <T> T checkNotNull​(T value,
                                         java.lang.String message)
        Ensures that the value is not null.
        Type Parameters:
        T - Type of the parameter.
        Parameters:
        value - the value to test for null.
        message - the message of the NullPointerException.
        Returns:
        the value if it is not null.
        Throws:
        java.lang.NullPointerException - with the message if the value is null.