18.2. Development guidelines
Fail fast. There are several levels of fail fast, from better to worse:
-
Fail Fast at compile time. For example: Don’t accept an
Objectas parameter if it needs to be aStringor anInteger. -
Fail Fast at startup time. For example: if the configuration parameter needs to be a positive
intand it’s negative, fail fast -
Fail Fast at runtime. For example: if the request needs to contain a double between
0.0and1.0and it’s bigger than1.0, fail fast. - Fail Fast at runtime in assertion mode if the detection performance cost is high. For example: If, after every low level iteration, the variable A needs to be equal to the square root of B, check it if and only if an assert flag is set to true (usually controlled by the EnvironmentMode).
-
Fail Fast at compile time. For example: Don’t accept an
ExceptionmessagesThe
Exceptionmessage must include the name and state of each relevant variable. For example:if (fooSize < 0) { throw new IllegalArgumentException("The fooSize (" + fooSize + ") of bar (" + this + ") must be positive."); }Notice that the output clearly explains what’s wrong:
Exception in thread "main" java.lang.IllegalArgumentException: The fooSize (-5) of bar (myBar) must be positive. at ...-
Whenever possible, the
Exceptionmessage must include context. Whenever the fix is not obvious, the
Exceptionmessage should include advice. Advice normally starts with the word maybe on a new line:Exception in thread "main" java.lang.IllegalStateException: The valueRangeDescriptor (fooRange) is nullable, but not countable (false). Maybe the member (getFooRange) should return CountableValueRange. at ...The word maybe is to indicate that the advice is not guaranteed to be right in all cases.
-
Generics. The
Solutionclass is often passed as a generic type parameter to subsystems. ThePlanningEntityclass(es) are rarely passed as a generic type parameter.

Where did the comment section go?
Red Hat's documentation publication system recently went through an upgrade to enable speedier, more mobile-friendly content. We decided to re-evaluate our commenting platform to ensure that it meets your expectations and serves as an optimal feedback mechanism. During this redesign, we invite your input on providing feedback on Red Hat documentation via the discussion platform.