bobobear / lambdaj

Automatically exported from code.google.com/p/lambdaj
Apache License 2.0
0 stars 0 forks source link

StringIndexOutOfBoundsException for expression with get(index) over list #31

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

Collection<IntervalsContainer> intervalsCollections = ...;
Date min = min(intervalsCollections, 
on(IntervalsContainer.class).getIntervals().get(0).getStart())

interface IntervalsContainer {  

        /** 
    * ordered by start date
    */
        List<Interval> getIntervals();

}

interface Interval{

    Date getStart();
    Date getEnd();

}

What is the expected output? What do you see instead?
expected output: some date
actual: 
java.lang.StringIndexOutOfBoundsException: String index out of range: 1
    at java.lang.String.substring(Unknown Source)
    at ch.lambdaj.util.IntrospectionUtil.getPropertyName(IntrospectionUtil.java:24)
    at ch.lambdaj.function.argument.Invocation.getInkvokedPropertyName(Invocation.java:54)
    at ch.lambdaj.function.argument.InvocationSequence.<init>(InvocationSequence.java:33)
    at ch.lambdaj.function.argument.ProxyArgument.invoke(ProxyArgument.java:37)
    at $Proxy500.get(Unknown Source)

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

Original issue reported on code.google.com by Zolochev...@gmail.com on 23 Jun 2010 at 10:09

GoogleCodeExporter commented 9 years ago
Hi Natalia,

I fixed the StringIndexOutOfBoundsException (the fix will be available since 
the release 2.3), but unfortunately your statement still cannot work. This is 
caused by the well-known generic reification problem. In your case the get(int) 
returns an Interval at compile time but only an Object at run time. That means 
that lambdaj creates a proxy of the Object class and then generates a 
ClassCastException when it tries to convert it in an Interval. The only 
solution I can see to this problem is to add to the IntervalsContainer a method 
like this:

public Interval getFirst() { return getIntervals().get(0); }

I hope this helps.

Thanks a lot
Mario

Original comment by mario.fu...@gmail.com on 23 Jun 2010 at 8:44