public class SanityManager
extends java.lang.Object
Assertions and debug checks can only be used for testing conditions that might occur in development code but not in production code. They are compiled out of production code.
Uses of assertions should not add AssertFailure catches or throws clauses; AssertFailure is under RuntimeException in the java exception hierarchy. Our outermost system block will bring the system down when it detects an assertion failure.
In addition to ASSERTs in code, classes can choose to implement an isConsistent method that would be used by ASSERTs, UnitTests, and any other code wanting to check the consistency of an object.
Assertions are meant to be used to verify the state of the system and bring the system down if the state is not correct. Debug checks are meant to display internal information about a running system.
AssertFailure
Modifier and Type | Field | Description |
---|---|---|
private static boolean |
AllDebugOff |
|
private static boolean |
AllDebugOn |
AllDebugOn and AllDebugOff override individual flags
|
static boolean |
ASSERT |
The build tool may be configured to alter
this source file to reset the static final variables
so that assertion and debug checks can be compiled out
of the code.
|
static boolean |
DEBUG |
|
static java.lang.String |
DEBUGDEBUG |
|
private static java.util.Hashtable<java.lang.String,java.lang.Boolean> |
DebugFlags |
DebugFlags holds the values of all debug flags in
the configuration file.
|
private static java.io.PrintWriter |
debugStream |
debugStream holds a pointer to the debug stream for writing out
debug messages.
|
Constructor | Description |
---|---|
SanityManager() |
Modifier and Type | Method | Description |
---|---|---|
static void |
ASSERT(boolean mustBeTrue) |
ASSERT checks the condition, and if it is
false, throws AssertFailure.
|
static void |
ASSERT(boolean mustBeTrue,
java.lang.String msgIfFail) |
ASSERT checks the condition, and if it is
false, throws AssertFailure.
|
static void |
DEBUG(java.lang.String flag,
java.lang.String message) |
The DEBUG calls provide the ability to print information or
perform actions based on whether a debug flag is set or not.
|
static void |
DEBUG_ALL_OFF() |
This can be used to have the SanityManager return FALSE
for any DEBUG_ON check.
|
static void |
DEBUG_ALL_ON() |
This can be used to have the SanityManager return TRUE
for any DEBUG_ON check.
|
static void |
DEBUG_CLEAR(java.lang.String flag) |
Set the named debug flag to false.
|
static boolean |
DEBUG_ON(java.lang.String flag) |
This can be called directly if you want to control
what is done once the debug flag has been verified --
for example, if you are calling a routine that prints to
the trace stream directly rather than returning a string to
be printed, or if you want to perform more (or fewer!)
|
static void |
DEBUG_PRINT(java.lang.String flag,
java.lang.String message) |
The DEBUG_PRINT calls provides a convenient way to print debug
information to the db2j.LOG file, The message includes a header
|
static void |
DEBUG_SET(java.lang.String flag) |
Set the named debug flag to true.
|
static java.io.PrintWriter |
GET_DEBUG_STREAM() |
|
static void |
NOTREACHED() |
|
static void |
SET_DEBUG_STREAM(java.io.PrintWriter pw) |
|
static void |
showTrace(java.lang.Throwable t) |
|
private static void |
showTrace(AssertFailure af) |
|
static void |
THROWASSERT(java.lang.String msgIfFail) |
THROWASSERT throws AssertFailure.
|
static void |
THROWASSERT(java.lang.String msg,
java.lang.Throwable t) |
THROWASSERT throws AssertFailure.
|
static void |
THROWASSERT(java.lang.Throwable t) |
THROWASSERT throws AssertFailure.
|
public static final boolean ASSERT
public static final boolean DEBUG
public static final java.lang.String DEBUGDEBUG
private static java.io.PrintWriter debugStream
private static java.util.Hashtable<java.lang.String,java.lang.Boolean> DebugFlags
private static boolean AllDebugOn
private static boolean AllDebugOff
public static final void ASSERT(boolean mustBeTrue)
AssertFailure
public static final void ASSERT(boolean mustBeTrue, java.lang.String msgIfFail)
AssertFailure
public static final void THROWASSERT(java.lang.String msgIfFail)
msgIfFail
- message to print with the assertionAssertFailure
public static final void THROWASSERT(java.lang.String msg, java.lang.Throwable t)
msg
- message to print with the assertiont
- exception to print with the assertionAssertFailure
public static final void THROWASSERT(java.lang.Throwable t)
t
- exception to print with the assertionAssertFailure
public static final void DEBUG(java.lang.String flag, java.lang.String message)
The message is output to the trace stream, so it ends up in
db2j.LOG. It will include a header line of
DEBUG
If the debugStream stream cannot be found, the message is printed to
System.out.
public static final boolean DEBUG_ON(java.lang.String flag)
Calls to this method should be surrounded with if (SanityManager.DEBUG) { } so that they can be compiled out completely.
public static final void DEBUG_SET(java.lang.String flag)
Calls to this method should be surrounded with if (SanityManager.DEBUG) { } so that they can be compiled out completely.
flag
- The name of the debug flag to set to truepublic static final void DEBUG_CLEAR(java.lang.String flag)
Calls to this method should be surrounded with if (SanityManager.DEBUG) { } so that they can be compiled out completely.
flag
- The name of the debug flag to set to falsepublic static final void DEBUG_ALL_ON()
public static final void DEBUG_ALL_OFF()
public static void SET_DEBUG_STREAM(java.io.PrintWriter pw)
public static java.io.PrintWriter GET_DEBUG_STREAM()
private static void showTrace(AssertFailure af)
public static void showTrace(java.lang.Throwable t)
public static void DEBUG_PRINT(java.lang.String flag, java.lang.String message)
DEBUG
If the debugStream stream cannot be found, the message is printed to
System.out.
public static void NOTREACHED()
Apache Derby V10.14 Internals - Copyright © 2004,2018 The Apache Software Foundation. All Rights Reserved.