Export to GitHub

lambdaj - issue #92

Lambdaj limitation with Dom4j


Posted on Mar 27, 2012 by Happy Giraffe

What steps will reproduce the problem? 1. Inject some list of dom4j Attributes (e.g element.attributes()) into a test for the method listed below:

import static ch.lambdaj.Lambda.having; import static ch.lambdaj.Lambda.selectFirst; import static org.hamcrest.CoreMatchers.equalTo;

import java.util.List;

import org.dom4j.Attribute; public class DocumentUtils {

public static String getAttributeValueFromListByName(
        List<Attribute> list, String name) {

    Attribute requiredAttribute = selectFirst(list,
            having((Attribute.class).getName(), equalTo(name)));

    String value = requiredAttribute.getValue();

    return value;

}

}

What is the expected output? What do you see instead?

I would expect the method to return the value of the specified (by name)attribute. Instead I get the following stacktrace:

ch.lambdaj.function.argument.ArgumentConversionException: Unable to convert the placeholder org.dom4j.Attribute in a valid argument at ch.lambdaj.function.argument.ArgumentsFactory.actualArgument(ArgumentsFactory.java:92) at ch.lambdaj.function.matcher.HasArgumentWithValue.havingValue(HasArgumentWithValue.java:70) at ch.lambdaj.Lambda.having(Lambda.java:1204)

What version of the product are you using? On what operating system?

lambdaj2.4 on windows 7

Please provide any additional information below.

Dom4j 1.6, Junit 4.9

Comment #1

Posted on May 15, 2012 by Swift Rabbit

Just making it clear that this effects all proxying of polymorphic classes, and not just this Dom4j scenario. Would love a fix!

Comment #2

Posted on Jul 8, 2012 by Helpful Cat

Am I wrong or are you missing to use the 'on' method like in:

Attribute requiredAttribute = selectFirst(list, having(ON(Attribute.class).getName(), equalTo(name)));

Comment #3

Posted on Nov 7, 2013 by Massive Cat

I've ran into exactly the same problem as the topic starter. And yes, the on method as stated by Mario solves the problem. I'm actually surprised to see that the original code compiles at all!

This issue can be closed as invalid.

Comment #4

Posted on Nov 7, 2013 by Massive Cat

Ah, the (Attribute.class).getName() code compiles because the Class object has a getName method. Easy as pie.

Status: New

Labels:
Type-Defect Priority-Medium