Is there a way to see what the values of the arguments that are sent into a method in Java? (source or bytecode)
I'm trying to print out the strings sent to the UI.
I'm using javassist/BCEL to examine the bytecode and to look for specific UI method (i.e. label.setText)
Then I'm trying figure out what are the strings that are being sent to those methods.
If the string is explicitly sent to that method(i.e. label.setText("hello")) I'm 'catching' the LDC declaration just before the method call and I'm done.
However, I'm not able to handle with complicated scenarios such as label.setText(bean.getName())
I need to come up with some kind of logic that will enable me to dig up the 'call hierarchy' in order to figure out the declaration of the string
I'm open to another alternatives if you have one...

Comments
Why don't you use
InvocationHandlerbased onProxyFactory?/*
* Copyright (c) 2002 Tikal Knowledge, Ltd.
* All Rights Reserved.
* Any distribution of the source code by other than Tikal Knowledge is prohibited.
*/
package com.tikalknowledge.openframe.proxy;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.tikalknowledge.openframe.ejb.Exceptions;
import com.tikalknowledge.openframe.exception.ApplicationException;
import com.tikalknowledge.openframe.exception.SystemException;
import com.tikalknowledge.openframe.util.Methods;
public class ObjectHandler implements InvocationHandler
{
private static Log log = LogFactory.getLog(ObjectHandler.class);
protected Object proxiedObject = null;
protected InvocationHandler proxiedObjectIH = null;
public ObjectHandler(Object proxiedObject)
{
this.proxiedObject = proxiedObject;
if ( proxiedObject != null )
{
// if target object is a proxy, send invocation through invocation handler
try
{
this.proxiedObjectIH = Proxy.getInvocationHandler(proxiedObject);
}
catch (IllegalArgumentException e)
{
this.proxiedObjectIH = null;
}
}
}
public Object invoke(Object proxy, Method m, Object[] args) throws Throwable
{
Object ret = null;
Object originalRet = null;
try
{
pre(proxy,m,args);
if ( this.proxiedObjectIH != null)
{
originalRet = this.proxiedObjectIH.invoke(this.proxiedObject,m,args);
}
else
{
originalRet = m.invoke(this.proxiedObject,args);
}
ret = post(proxy,m,args,originalRet);
}
catch (InvocationTargetException ite)
{
log.debug(ite);
Exception e = (Exception) Exceptions.getCause(ite);
if ( Methods.isThrowableInMethodSigniture(m,e))
throw e;
else
throw Exceptions.translate(e);
}
return ret;
}
protected void pre(Object proxy, Method m, Object[] args) throws SystemException,ApplicationException
{
}
protected Object post(Object proxy, Method m, Object[] args,Object ret) throws SystemException,ApplicationException
{
return ret;
}
}
invoking the method is not a solution for me (if that what you meant)
lets assume I have the following code:
class Person {
String name;
public void setName(String name){this.name = name;}
public String getName(){return name;}
}
class PersonForm {
......
public void createGui (Person person) {
....
JPanel panel = new JPanel();
JLabel name = new JLabel("Name:");
JTextField field;
if(person != null) {
field = new JTextField(person.getName());
} else {
field = new JTextField();
System.out.println("error - person is null");
}
panel.add(.....
....
}
public static void main(String[] args){
Person p = new Person();
p.setName("David");
MyClass.createGui(p);
}
}
I'm pooling out from the constant pool (bytecode) all the strings in the code and now I have:
- Name:
- error - person is null
- David
I need to figure out which of the strings are shown in the UI controls.
as a source I have both - The bytecode (preferred) and the source code
I still do not understand what are you trying to do and where exactly is the problem.
my purpose is to drop the string that are going to be presented in the UI into a file where my input is the product jar files (preferred) or the source file
If you will wrap the Person construction
using the Proxy and InvocationHandler,
you will be able to catch all method invocation
(person.getName())
A clarification - since I'm looking for 85% coverage and up - run time solution for capturing the strings is not an option (unless you can suggest a great automatic tool...)