After investigation, I think this problem can probably be fixed by changing the following two places in AnchorMethodInvokeAction,java I've tested my local changes and it works, but not sure if there will be any side effects.
Neeraj could you please comment on this. Xiping ======================================================= change 1: public static void validateActualParameters(SPLSymbolTable symTab, String classNameOrVariableName, String methodName, List pList) throws SPLException { MethodSymbol methodSym = (MethodSymbol) symTab .getSymbol(classNameOrVariableName + "." + methodName); List argTypeList = methodSym.getArgumentList(); Iterator formalParamTypeIt = argTypeList.iterator(); Iterator actualParamIt = pList.iterator(); if (argTypeList.size() == pList.size()) { while (formalParamTypeIt.hasNext() && actualParamIt.hasNext()) { Argument formalArg = (Argument) formalParamTypeIt.next(); Expression actualParam = (Expression) actualParamIt.next(); //Xiping 05/29/09 // if (!TypeResolver.isTypeAssignableForEquality(formalArg // .getType(), actualParam.getType()) // || formalArg.getIsArray() != actualParam.isArray ()) if (!TypeResolver.isTypeAssignableForEquality(formalArg .getType(), actualParam.getType())) { throw new SPLException( Messages .getString( "SPL_METHOD_PASSED_ARGUMENTS_EXCEPTION_MSG") + " " + methodName); } } } else { System.err .println("Number of Formal and passed parameters don't match for method " + methodName); // throw new SPLException("Number of Formal and passed parameters don't match for method " // + methodName); } } change 2: public static Object invokeClassMethod(SPLSymbolTable symTab, String className, String qualifier, String methodName, List paramList, Object targetObject) throws SPLException { List parameterObjects = new ArrayList(); try { MethodSymbol methodSym = (MethodSymbol) symTab.getSymbol (className + "." + methodName); List argTypeList = methodSym.getArgumentList(); for (int i = 0; i < paramList.size(); i++) { Expression exp = (Expression) paramList.get(i); if (exp instanceof AssignmentExpression) { //System.out.println("assignment Expression"); Expression lhsExpression = null; Expression rhsExpression = null; AssignmentExpression assignmentExpression = (AssignmentExpression) exp; if (assignmentExpression.getLHSExpression() instanceof org.apache.imperius.spl.external.Expression) { lhsExpression = (Expression) assignmentExpression .getLHSExpression(); } if (assignmentExpression.getRHSExpression() instanceof org.apache.imperius.spl.external.Expression) { rhsExpression = (Expression) assignmentExpression .getRHSExpression(); } if ((lhsExpression == null) || (rhsExpression == null)) { logger .severe("LHS or RHS or argument in method call is null : " + lhsExpression.toString() + " " + rhsExpression); throw new SPLException(Messages.getString( "SPL_ASSIGNMENT_EXP_EXCEPTION_MSG", new Object[] { lhsExpression, rhsExpression })); } //System.out.println("lhsExpression class "+ lhsExpression.getClass()); //System.out.println("lhsExpression getPropertyName() "+ ((PrimaryExpression) lhsExpression).getPropertyName()); // ((PrimaryExpression)lhsExpression).getPropertyName (); String keyName = ((PrimaryExpression) lhsExpression) .getclassNameOrInstanceVariableName(); //System.out.println("argument name= " + keyName); Object keyValue = rhsExpression.evaluate(); //System.out.println("argument value= " + keyValue); String referenceTypeName = ""; if (TypeResolver.isReference(rhsExpression.getType())) { referenceTypeName = rhsExpression.getType() .getReferenceTypeName(); } if (keyValue != null) { Argument arg = new ArgumentImpl (rhsExpression.getType() .getType(), keyName, rhsExpression.isArray (), referenceTypeName); arg.setValue(keyValue); //System.out.println("created new arg :"+keyName+" "+keyValue.toString()); /* * Expression expression=(Expression)pList.get(i); String * nameAndValue=(String)expression.evaluate(); Key */ parameterObjects.add(arg); } } else { Object result = exp.evaluate(); boolean isArgCreated = false; if(argTypeList != null && argTypeList.size() > 0) { Argument tempArg = null; if(i < argTypeList.size()) { tempArg = (Argument)argTypeList.get(i); if(TypeResolver.isReference(tempArg.getType ())) { if (TypeResolver.OBJECT_STRING.equals (tempArg .getType ().getReferenceTypeName()) && TypeResolver.isString(exp.getType())) { Argument arg = new ArgumentImpl(tempArg .getType ().getType(), null, tempArg .getType ().getIsArray(), TypeResolver.OBJECT_STRING); arg.setValue(result); parameterObjects.add (arg); isArgCreated = true; } } } else { // throw exception } } if(!isArgCreated) { //Xiping 05/29/09 Argument tempArg = null; tempArg = (Argument)argTypeList.get(i); // Argument arg = new ArgumentImpl(exp.getType ().getType(), // null, exp.isArray(), null); null, tempArg.getType().getIsArray(), null); arg.setValue(result); parameterObjects.add(arg); } } } Actuator ac = ActuatorFactory.getActuator(); Object result = ac.invokeMethod(className, qualifier, targetObject, methodName, parameterObjects); //System.out.println("method invokation complete : "+className +" "+qualifier+" "+methodName+" "+targetObject); //System.out.println("method invokation result of invokation : "+result); // TO DO COMPARE RESULT WITH CONSTANT if (result == null) result = ""; return result; } catch (SPLException e) { logger.severe(e.getMessage()); logger.exiting(sourceClass, Thread.currentThread().getName() + " " + "execute"); // return null; throw e; } } Xiping Wang/Watson/i...@i BMUS To imperius-dev@incubator.apache.org 05/28/2009 04:28 cc PM Subject Re: [jira] Updated: (IMPERIUS-28) Please respond to byte[] method return type does not imperius-...@incu match formal parameter bator.apache.org Hi Neeraj, You are right, but the flag gets set when a policy is parsed without looking at the corresponding anchor class. A mismatch could occur at evaluation time depending the return type of a method, Xiping IBM TJ Watson Research Center Neeraj Joshi/Durham/i...@ibmus Neeraj Joshi/ Durham /i...@i BMUS To imperius-...@incubator.apache.or 05/28/ g 2009 01:48 cc PM Subject Please respond to imperius-...@incubator.apache Re: [jira] Updated: .org (IMPERIUS-28) byte[] method return type does not match formal parameter Hey guys, There is an isArray variable that gets set automatically based on reflection. There must be some other issue involved here Neeraj ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ "The light at the end of the tunnel...may be you" Neeraj Joshi WebSphere XD - Compute Grid AIM, IBM Apache Imperius - http://incubator.apache.org/imperius ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ From: Xiping Wang/Watson/i...@ibmus To: imperius-dev@incubator.apache.org Cc: imperius-dev@incubator.apache.org Date: 05/28/2009 01:01 PM Subject: Re: [jira] Updated: (IMPERIUS-28) byte[] method return type does not match formal parameter Let's take a look at the line in red in the policy you provided. In you example, you have getByteArray() method that returns a byte[] return type. Assume I add another method to the anchor class with the same name but renturns a byte type. How do you write a SPL policy to distinguish between these two? Import Class com.ibm.watson.pml.bytearray.ByteArrayFactory:baf; Strategy Execute_All_Applicable; Policy { Condition { baf.takeByteArray(baf.getByteArray()) } Decision { ReturnValue(\"OK\") } }:1; Xiping IBM TJ Watson Research Center David Wood/Watson/i...@ibmus David Wood/Watson/i...@ibmus 05/28/2009 12:23 PM Please respond to imperius-dev@incubator.apache.org To imperius-dev@incubator.apache.org cc imperius-dev@incubator.apache.org Subject Re: [jira] Updated: (IMPERIUS-28) byte[] method return type does not match formal parameter I don't think this is an SPL specification issue. This is strictly a problem with the definition of the method's return type as indicated in the Java Class object. Somehow that definition is not being picked up as an array and instead just as a single byte. It _is_ getting the formal parameter definition correct (i.e. a byte[]). David Wood Policy Technologies Group IBM TJ Watson Research Center daw...@us.ibm.com 914-784-5123 (office), 914-396-6515 (mobile) From: Xiping Wang/Watson/i...@ibmus To: imperius-dev@incubator.apache.org Cc: imperius-dev@incubator.apache.org Date: 05/28/2009 11:51 AM Subject: Re: [jira] Updated: (IMPERIUS-28) byte[] method return type does not match formal parameter David, It seems to me that Imperius is not capable of handling array return type because the SPL does not distinguish between primitive return type and array return type syntactically. Xiping IBM T.J. Watson Research Center "David Wood (JIRA)" <j...@apache.org> "David Wood (JIRA)" <j...@apache.org> 05/26/2009 08:29 PM Please respond to imperius-dev@incubator.apache.org To imperius-dev@incubator.apache.org cc Subject [jira] Updated: (IMPERIUS-28) byte[] method return type does not match formal parameter [ https://issues.apache.org/jira/browse/IMPERIUS-28?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] David Wood updated IMPERIUS-28: ------------------------------- Attachment: ByteArrayFactory.java PolicyParser.java > byte[] method return type does not match formal parameter > --------------------------------------------------------- > > Key: IMPERIUS-28 > URL: https://issues.apache.org/jira/browse/IMPERIUS-28 > Project: Imperius > Issue Type: Bug > Environment: Windows, Java 1.5 > Reporter: David Wood > Assignee: Bill Stoddard > Attachments: ByteArrayFactory.java, PolicyParser.java > > Original Estimate: 96h > Remaining Estimate: 96h > > It appears that a method's byte[] return type is not being properly matched with a byte[] method argument. The attached Java program includes a policy that passes the byte[] return value of a method to another method that expects the same. This gives the following message: > May 26, 2009 8:20:52 PM org.apache.imperius.spl.parser.compiler.SPLTreeParser identPrimary > SEVERE: main TreeParser::Exception creating Expression at line 4 : Formal and passed parameter types don't match for method takeByteArray > Formal and passed parameter types don't match for method takeByteArray > May 26, 2009 8:20:52 PM org.apache.imperius.spl.datastore.impl.PolicyParserImpl parseFile > SEVERE: Error encountered while parsing tree > Exception in thread "main" org.apache.imperius.spl.parser.exceptions.SPLException: Error encountered while parsing tree > at org.apache.imperius.spl.datastore.impl.PolicyParserImpl.parseFile (PolicyParserImpl.java:166) > at org.apache.imperius.spl.datastore.impl.PolicyParserImpl.createInternalPolicyObject (PolicyParserImpl.java:96) > at com.ibm.watson.pml.bytearray.PolicyParser.main(PolicyParser.java:55) > I've attached both the Java program and the ByteArrayFactory interface that is used in the policy (also found in the Java file). -- This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online.