Export to GitHub

lambdaj - issue #95

ConstructorArgumentConverter / project can't take enum as argument.


Posted on Jun 7, 2012 by Grumpy Bear

What steps will reproduce the problem? 1. Use ConstructorArgumentConverter with a class who's constructor takes an enum. (I'm really not sure if the enum is the problem. Just a guess.)

What version of the product are you using? On what operating system? 2.4 on Linux, JDK 6.

Please provide any additional information below.

I'm sorry for not providing a detailed example, so I will understand if the issue will be rejected.

Here is my call:

List<GenericPRB> genPrbList = convert(prbList, new ConstructorArgumentConverter<PRB, GenericPRB>(GenericPRB.class, on(PRB.class), az));

The GenericPRB class's constructor takes a PRB and an enum (az in this case).

Here is the stack trace:

FAILED: TestGetAvgPrbList ch.lambdaj.function.argument.ArgumentConversionException: Unable to convert the placeholder AZ in a valid argument at ch.lambdaj.function.argument.ArgumentsFactory.actualArgument(ArgumentsFactory.java:92) at ch.lambdaj.function.convert.ArgumentConverter.<init>(ArgumentConverter.java:29) at ch.lambdaj.function.convert.ConstructorArgumentConverter.<init>(ConstructorArgumentConverter.java:35)

I get the same error if I try to use 'project':

List<GenericPRB> genPrbList = project(prbList, GenericPRB.class, on(PRB.class), az);

Until this is fixed (if it is indeed a bug), I've found a work around by writing my own special converter class.

Comment #1

Posted on Jun 7, 2012 by Grumpy Bear

Is this issue due to the known limitations? http://code.google.com/p/lambdaj/wiki/KnownLimitations

I was hoping since the enum (final class) wasn't being used with on(), it would be okay.

Comment #2

Posted on Jul 8, 2012 by Helpful Cat

You cannot use the ConstructorArgumentConverter in this way. It is supposed to convert an instance of the class F into an instance of the T by invoking a constructor of the class T passing to it some values taken from the fields of F as in the following example:

new ConstructorArgumentConverter(GenericPRB.class, on(PRB.class).getValue1(), on(PRB.class).getValue2(), ...);

You cannot use in this converter values that are not taken from the F instance.

Status: Invalid

Labels:
Type-Defect Priority-Medium