0

For anyone familiar with lambdaj (not I) you will have seen this stacktrace, or some variation, before:

ch.lambdaj.function.argument.ArgumentConversionException: Unable to convert the placeholder org.dom4j.tree.AbstractAttribute 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)

My understadning is that this happens through a limitation of lambdaj with final classes.

I get the above when testing the following code:

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.tree.AbstractAttribute;
public class DocumentUtils {

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

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

        String value = requiredAttribute.getValue();

        return value;

    }

}

I had been using dom4j's Attribute interface, getting the same problem, then thought maybe lambdaj doesn't like interfaces.. so I switched to the AbstractAttribute abstract class.

Is there an issue with lambdaj and abstract classes? Or is my method just pants? Any ideas how to solve this?

FYI: I'm using lambdaj 2.4 and dom4j 1.6

Thanks a lot in advance.

HellishHeat
  • 2,280
  • 4
  • 31
  • 37
  • Just to be clear; I'm only interested in whether or not this can be implemented in lambdaj. When I say "Any ideas how to solve this?", I mean "solve" using lambdaj. Thanks! (I'm also wondering if commentin gwill bump my post, I created this question last night *drums fingers* ) – HellishHeat Mar 27 '12 at 07:32

2 Answers2

0

If you're using lambdaj 2.4 you're lucky because this issue has been fixed in that release. The problem and its solution is described in the first point of the release notes of lambdaj 2.4.

In particular lambdaj uses an internal heuristic to create Argument's placeholder, but it doesn't work in some cases, so you can override it as explained there.

Mario Fusco
  • 13,548
  • 3
  • 28
  • 37
  • Thanks Mario, Am I to take it, from your answer, that the ArgumentConversionException I am getting is not relating to my AbstractAttribute, but to the String .getName()? So I can use some variation of the solution described in "point 1" in the release notes to sort my problem? – HellishHeat Mar 27 '12 at 10:15
  • No this is not the point. Anyway forget what I wrote before: it is intended to be used only for final classes and this is not your case. Indeed lambdaj should always be able to create argument placeholders for abstract classes and for sure for interfaces since in this last case it can use the native java proxy mechanism. I am afraid you hit a lambdaj bug. Could you please open a issue on the lambdaj issue tracking attaching your failing test case. If possible, please use the interface instead of the abstract class. Thanks – Mario Fusco Mar 27 '12 at 10:57
  • Sure, I'll create an issue this evening. Thanks for clearing that up. – HellishHeat Mar 27 '12 at 11:02
0

Issue 92 has been raised with lambdaj, as requested by Mario Fusco (LambdaJ Developer)

HellishHeat
  • 2,280
  • 4
  • 31
  • 37