}
/* Use classname@hashcode */
- else return obj.getClass().getName() + "@" + Integer.toString(obj.hashCode(),16);
+ else return obj.getClass().getName() + "@" + Integer.toHexString(obj.hashCode());
/* Object.hashCode() can be override and may thow an exception */
} catch (Exception ex) {
- return obj.getClass().getName();
+ return obj.getClass().getName() + "@FFFFFFFF";
}
}
return sb.toString();
}
+
+ protected Object[] formatObjects(Object[] args) {
+ for (int i = 0; i < args.length; i++) {
+ args[i] = formatObj(args[i]);
+ }
+
+ return args;
+ }
}
\ No newline at end of file
public void testEnterWithThisAndArray() {
Object arg1 = new String[] { "s1", "s2" };
Object arg2 = new char[] { 'a', 'b', 'c' };
- trace.enter("testEnterWithThisAndArgs",this,new Object[] { arg1, arg2 });
+ trace.enter(getName(),this,new Object[] { arg1, arg2 });
}
public void testEnterWithThisAndCollection() {
Object arg1 = new ArrayList();
- trace.enter("testEnterWithThisAndArgs",this,new Object[] { arg1 });
+ trace.enter(getName(),this,new Object[] { arg1 });
}
public void testEnterWithThisAndTraceable () {
Object arg1 = new Traceable() {
public String toTraceString() {
- return "Traceable";
+ return getClass().getName() + "[Traceable]";
}
};
- trace.enter("testEnterWithThisAndArgs",this,new Object[] { arg1 });
+ trace.enter(getName(),this,new Object[] { arg1 });
+ }
+
+ public void testEnterWithThisAndToStringException () {
+ Object arg1 = new Object() {
+
+ public String toString() {
+ throw new RuntimeException("toString() can throw an Exception");
+ }
+
+ };
+ trace.enter(getName(),this,new Object[] { arg1 });
+ }
+
+ public void testEnterWithThisAndHashCodeException () {
+ Object arg1 = new Object() {
+
+ public int hashCode() {
+ throw new RuntimeException("hashCode can throw an Exception");
+ }
+
+ };
+ trace.enter(getName(),this,new Object[] { arg1 });
+ }
+
+ public void testEnterWithThisAndClassLoader () {
+ Object arg1 = new ClassLoader() {
+
+ public String toString() {
+ throw new Error("Don't call ClassLoader.toString()");
+ }
+
+ };
+ trace.enter(getName(),this,new Object[] { arg1 });
}
public void testEnterWithThis() {
if (logger.isLoggable(Level.FINE)) {
logger.entering(name,methodName,formatObj(thiz));
if (args != null && logger.isLoggable(Level.FINER)) {
- logger.entering(name,methodName,args);
+ logger.entering(name,methodName,formatObjects(args));
}
}
}
public void exit(String methodName, Object ret) {
if (logger.isLoggable(Level.FINE)) {
- logger.exiting(name,methodName,ret);
+ logger.exiting(name,methodName,formatObj(ret));
}
}
if (logger.isLoggable(Level.FINE)) {
logger.logp(Level.FINER,name,methodName,"EVENT",formatObj(thiz));
if (args != null && logger.isLoggable(Level.FINER)) {
- logger.logp(Level.FINER,name,methodName,"EVENT",args);
+ logger.logp(Level.FINER,name,methodName,"EVENT",formatObjects(args));
}
}
}