Andrus,

Sorry, it came out unclearly in the email. The exception, an ExpressionException, doesn't have a stack trace.

Here is a standalone snippet that will create the problem:

private void matchAllTest() {
   HashMap map = new HashMap();
   map.put("test", "test");
   Expression qual = ExpressionFactory.matchAllExp(map, Expression.AND);
}

I thought that ought to create a valid expression, but if you step through matchAllExp there is an exception thrown, and it doesn't seem to depend on the values of the map entry. I can't see how the unit test doesn't throw it. Here is the stack as the exception is about to be thrown (explicitly using throw):

Thread [main] (Suspended) ASTAnd(AggregateConditionNode).jjtAddChild(Node, int) line: 125 ASTAnd(SimpleNode).setOperand(int, Object) line: 187 ExpressionFactory.matchAllExp(Map, int) line: 298 SelectObjectPage2.matchAllTest()

Hope that is clearer. I've worked around it fairly simply.

Marcel

Andrus Adamchik wrote:
Marcel,

Could you post the actual code and exception stack trace? (sorry, I am tired at the end of the day and can't make sense of what you wrote). BTW, this unit test works:

    public void testMatchAllExp() throws Exception {
        // create expressions and check the counts,
        // leaf count should be (2N) : 2 leafs for each pair
        // node count should be (2N + 1) for nodes with more than 1 pair
        // and 2N for a single pair : 2 nodes for each pair + 1 list node
        // where N is map size

        // check for N in (1..3)
        for (int n = 1; n <= 3; n++) {
            Map map = new HashMap();

            // populate map
            for (int i = 1; i <= n; i++) {
                map.put("k" + i, "v" + i);
            }

Expression exp = ExpressionFactory.matchAllExp(map, Expression.LESS_THAN);
            assertNotNull(exp);
            handler.traverseExpression(exp);

            // assert statistics
            handler.assertConsistency();
            assertEquals("Failed: " + exp, 2 * n, handler.getLeafs());
assertEquals("Failed: " + exp, n < 2 ? 2 * n : 2 * n + 1, handler
                    .getNodeCount());
        }
    }




On Jul 24, 2006, at 9:38 PM, Marcel wrote:


As far as I can tell there is a bug in ExpressionFactory.*matchAllExp*(java.util.Map map, int type).

With a map of keys and values, an exception will always arise here:

Thread [main] (Suspended) ASTAnd(AggregateConditionNode).jjtAddChild(Node, int) line: 120 ASTAnd(SimpleNode).setOperand(int, Object) line: 187 ExpressionFactory.matchAllExp(Map, int) line: 298

jjtAddChild throws an exception whenNode is not of type ConditionNode or AggregateConditionNode. However, the Node parameter is just the Object parameter from setOperand, which is called from matchAllExp as:

exp.setOperand(0, new ASTObjPath(entry.getKey()));

Where entry.getKey() is the object path (in my case just the name of an object attribute). ASTObjPath is not of the correct type, so an exception is thrown everytime, regardless of what entry.getKey() happens to be.

Folks with more experience? I'll try just stringing my own expression together for now.

Marcel



Reply via email to