Join 34,000+ subscribers and receive articles from our
blog about software quality, testing, QA and security.

enterMethod with arguments not working as expected in java


I expected that ‘enterMethod(Object instance, String methodName, Object[] args)’ will be logged as ‘mypackage.myclass.methodNameb[/b]’, but it seems that the arguments aren’t logged. I don’t see the problem in my code:

private void setAutoBuild(boolean value) {
    session.enterMethod(this, "setAutoBuild", new Object[] { value });
    session.leaveMethod(this, "setAutoBuild");

It results in the simple log entry ‘de.se_elektronic.ixPert.eddc.VariableSynchronizer.setAutoBuild’ without arguments. Any suggestions?



Thanks for your message. The overloaded variant of the enterMethod method with an additional object array argument can be used to format the method string (similar to how Java’s MessageFormat.format works). So to include the boolean value in the resulting log message, you can just write this:

session.enterMethod(this, "setAutoBuild({0})", new Object[] { value });

This also works for a lot of other SmartInspect methods (not just enter/leaveMethod) and is useful to include additional data in log messages. I hope this helps!