Class IndexBoundsException

All Implemented Interfaces:
Serializable
Direct Known Subclasses:
ArrayCapacityException

public class IndexBoundsException
extends IndexOutOfBoundsException
Proper version of IndexOutOfBoundsException / ArrayIndexOutOfBoundsException.

As usual, they put programmatic relevant data into contextless plain strings in class ArrayIndexOutOfBoundsException. Funny thing is with this class they at least tried to do it right (one parameter index), but still failed hilariously (missing array bound parameter and again stuffing the argument value into a plain string).

Also note from an architectual / design / API point of view that (apart from ArrayCapacityExceptionbeeing a JVM-technical special case), index bounds exceptions should not distinct between comming from an array or another index-based data structure as this is an implementation detail. Especially since Java exceptions are hardcoded classes instead of multiple-inheritance-of-type-viable proper types (interfaces), it even MUST not be differentiated.

So again, one has to do everything by oneself properly.

See Also:
Serialized Form
  • Constructor Details

  • Method Details

    • messageBody

      public static final String messageBody()
    • startIndex

      public final long startIndex()
    • indexBound

      public final long indexBound()
    • index

      public final long index()
      The index value used in the accessing attempt causing this exception.

      Note that this value might have overflown depending on the reporting logic.

    • message

      public final String message()
      Sadly, the Throwable implementation uses #getMessage() directly to print the exception. This is a concern conflict: getMessage should actually be the getter for the explicit message. But it is used as the String assembling method as well. So a output method generically assembling the output string must override the getter. As this hides the actual getting functionality, a workaround accessor method has to be provided for potential subclasses.
      Returns:
      the explicit message string passed to the constructor when creating this instance.
    • assembleDetailString

      public String assembleDetailString()
    • assembleOutputString

      public String assembleOutputString()
    • getMessage

      public String getMessage()
      Returns an assembled output String due to bad method design in Throwable. Albeit being named "getMessage" by the JDK developers, this method should be seen as "assembleOutputString" as this is its purpose. For the actual message getter, see message().
      Overrides:
      getMessage in class Throwable
      Returns:
      this exception type's generic message plus an explicit message if present.