Use of generics in helper class methods
andyoverton Jul 25, 2012 7:09 AMHi,
I am new to using Byteman and have come across an issue that I can't seem to resolve and can't find any information on.
I've cut out any extra code and just put in the code i'm having difficulty with to make it easier to follow.
I have a main class as follows :
class AppMain
{
public static void main(String[] args)
{
String[] testArray = {"One", "Two", "Three"};
}
}
I then have a helper class as follows :
import org.jboss.byteman.rule.Rule;
import org.jboss.byteman.rule.helper.Helper;
public class MyHelper extends Helper
{
protected MyHelper(Rule rule)
{
super(rule);
}
public <E> void displayArray(E[] inputArray)
{
for (E element : inputArray)
{
System.out.printf("%s ", element);
}
System.out.println();
}
public void displayArray2(String[] strings)
{
for (String s : strings)
{
System.out.println("S = " + s);
}
}
}
Now, what I want to do is to call the displayArray method passing in the String array created in Main and have it display the contents.
My rule is as follows :
RULE MY TEST RULE
CLASS AppMain
METHOD main
HELPER MyHelper
AT EXIT
IF true
DO displayArray($testArray);
ENDRULE
If I call displayArray2 then it works fine. However, if I call displayArray which uses generics then I get the following error:
Rule.execute called for MY TEST RULE_1
Rule.ensureTypeCheckedCompiled : error type checking rule MY TEST RULE
org.jboss.byteman.rule.exception.TypeException: DollarExpression.typeCheck : invalid expected type java.lang.Object[] for bound parameter $testArray file appmain.btm line 16
at org.jboss.byteman.rule.expression.DollarExpression.typeCheck(DollarExpression.java:172)
at org.jboss.byteman.rule.expression.MethodExpression.findMethod(MethodExpression.java:245)
at org.jboss.byteman.rule.expression.MethodExpression.typeCheck(MethodExpression.java:172)
at org.jboss.byteman.rule.Action.typeCheck(Action.java:106)
at org.jboss.byteman.rule.Rule.typeCheck(Rule.java:523)
at org.jboss.byteman.rule.Rule.ensureTypeCheckedCompiled(Rule.java:449)
at org.jboss.byteman.rule.Rule.execute(Rule.java:670)
at org.jboss.byteman.rule.Rule.execute(Rule.java:651)
at AppMain.main(AppMain.java:8)
Is it possible to call a method which has a generic parameter? Or can someone point me in the direction of more information on this as I can't find any anywhere.
Thanks in advance,
Andy