-
Enhancement
-
Resolution: Future Project
-
P4
-
None
-
5.0
-
x86
-
windows_2000
A DESCRIPTION OF THE REQUEST :
The method ErrorManager.error(String msg, Exception ex, int code) is unnecessarily restrictive in requiring the ex parameter to be of type Exception, rather than the more generic Throwable type.
JUSTIFICATION :
In custom java.util.logging.Handler implementation, it is sometimes useful to pass a caught exception of type Throwable to the Handler's ErrorManager.error() method.
Similarly, in an implementation of Handler.publish(LogRecord), it would sometimes be desirable to pass the value returned from LogRecord.getThrown() directly into the ErrorManager.error() method. An example scenario is when the LogRecord instance passed to Handler.publish() is malformed and cannot be handled by the Handler. Here it would be useful for the ErrorManager to still publish the original Throwable contained within the LogRecord.
The ErrorManager.error(String msg, Exception ex, int code) method doesn't accept a Throwable parameter, even though the ex parameter is used
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Within a custom java.util.logging.Handler implementation...
- Acquire a Throwable instance, either from a catch(Throwable) statement, or from a supplied LogRecord, as in the example below.
- Pass the Throwable object directly to ErrorManager.error().
MyHandler.publish(LogRecord lr)
{
if (lr.getLoggerName() == null)
{
Throwable thrown = lr.getThrown();
getErrorManager.error("Invalid LogRecrod for this exception.", thrown, ErrorManager.FORMAT_FAILURE);
}
}
ACTUAL -
- Test whether the Throwable is an instance of Exception. If so, then downcast the Thorwable to an Exception and pass it to ErrorManager.error(). Otherwise, find some other way to handle the problem.
MyHandler.publish(LogRecord lr)
{
if (lr.getLoggerName() == null)
{
Throwable thrown = lr.getThrown();
if (thrown instanceof Exception)
{
Exception ex = (Exception)thrown;
getErrorManager.error("Invalid LogRecrod for this exception.", ex, ErrorManager.FORMAT_FAILURE);
}
else
// report it some other way...
}
}
---------- BEGIN SOURCE ----------
See "ActualBehaviour" example, above.
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
See "Expected Behaviour" example, above.
###@###.### 2005-03-11 06:17:59 GMT
The method ErrorManager.error(String msg, Exception ex, int code) is unnecessarily restrictive in requiring the ex parameter to be of type Exception, rather than the more generic Throwable type.
JUSTIFICATION :
In custom java.util.logging.Handler implementation, it is sometimes useful to pass a caught exception of type Throwable to the Handler's ErrorManager.error() method.
Similarly, in an implementation of Handler.publish(LogRecord), it would sometimes be desirable to pass the value returned from LogRecord.getThrown() directly into the ErrorManager.error() method. An example scenario is when the LogRecord instance passed to Handler.publish() is malformed and cannot be handled by the Handler. Here it would be useful for the ErrorManager to still publish the original Throwable contained within the LogRecord.
The ErrorManager.error(String msg, Exception ex, int code) method doesn't accept a Throwable parameter, even though the ex parameter is used
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Within a custom java.util.logging.Handler implementation...
- Acquire a Throwable instance, either from a catch(Throwable) statement, or from a supplied LogRecord, as in the example below.
- Pass the Throwable object directly to ErrorManager.error().
MyHandler.publish(LogRecord lr)
{
if (lr.getLoggerName() == null)
{
Throwable thrown = lr.getThrown();
getErrorManager.error("Invalid LogRecrod for this exception.", thrown, ErrorManager.FORMAT_FAILURE);
}
}
ACTUAL -
- Test whether the Throwable is an instance of Exception. If so, then downcast the Thorwable to an Exception and pass it to ErrorManager.error(). Otherwise, find some other way to handle the problem.
MyHandler.publish(LogRecord lr)
{
if (lr.getLoggerName() == null)
{
Throwable thrown = lr.getThrown();
if (thrown instanceof Exception)
{
Exception ex = (Exception)thrown;
getErrorManager.error("Invalid LogRecrod for this exception.", ex, ErrorManager.FORMAT_FAILURE);
}
else
// report it some other way...
}
}
---------- BEGIN SOURCE ----------
See "ActualBehaviour" example, above.
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
See "Expected Behaviour" example, above.
###@###.### 2005-03-11 06:17:59 GMT