Class CommitOperations.MaybeIOE

java.lang.Object
org.apache.hadoop.fs.s3a.commit.impl.CommitOperations.MaybeIOE
Enclosing class:
CommitOperations

public static class CommitOperations.MaybeIOE extends Object
A holder for a possible IOException; the call maybeRethrow() will throw any exception passed into the constructor, and be a no-op if none was. Why isn't a Java 8 optional used here? The main benefit would be that maybeRethrow() could be done as a map(), but because Java doesn't allow checked exceptions in a map, the following code is invalid
   exception.map((e) -> {throw e;}
 
As a result, the code to work with exceptions would be almost as convoluted as the original.
  • Field Details

  • Constructor Details

    • MaybeIOE

      public MaybeIOE(IOException exception)
      Construct with an exception.
      Parameters:
      exception - exception
  • Method Details

    • getException

      public IOException getException()
      Get any exception.
      Returns:
      the exception.
    • hasException

      public boolean hasException()
      Is there an exception in this class?
      Returns:
      true if there is an exception
    • maybeRethrow

      public void maybeRethrow() throws IOException
      Rethrow any exception.
      Throws:
      IOException - the exception field, if non-null.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • of

      public static CommitOperations.MaybeIOE of(IOException ex)
      Get an instance based on the exception: either a value or a reference to NONE.
      Parameters:
      ex - exception
      Returns:
      an instance.