bobobear / lambdaj

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

Closure println = closure();{ of(system.out).println(var(string.class)); } not working with IBM JVM #14

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
This example is not working with IBM JVM (throws NullPointerException), 
but works with the Sun version -->
Due to the fact that
IBM System.out.getClass()=com.ibm.jvm.io.ConsolePrintStream
and
Sun System.out.getClass()=java.io.PrintStream

the IBM impl. is a final class, not the case with the Sun one.

I have found that the LambdaJ class ProxyUtil checks if the closed object 
is of final class. I am not sure why is this the case???

It works though if I wrap it with a PrintStream (PrintStream(System.out))

Regards

Georgios

Original issue reported on code.google.com by georgiad...@googlemail.com on 26 Aug 2009 at 11:14

GoogleCodeExporter commented 9 years ago
Yes, it does that because after that it trieds to wrap the actual passed class 
into 
a Enhancer generated subclass, which of course will fail if the class is final. 
Is a 
solution to that? Maybe the ClassImposterizer can find the first available non 
final 
superclass of the passed class and enhance that one instead? The cost will be 
of 
course that it will narrow thenumber of methods available to be called through 
the 
closure, but then again, I suppose better that the fail safe 
NullPointerException 
thrown.

Hope that makes sense.

Regards

Georgios

Original comment by georgiad...@googlemail.com on 26 Aug 2009 at 11:31

GoogleCodeExporter commented 9 years ago
It is a well known limitation that lambdaj doesn't work with final classes. 
Even to
look for the first available non final superclass it is not a viable workaround 
since
it causes to throw a ClassCastException.

Original comment by mario.fu...@gmail.com on 26 Aug 2009 at 11:55

GoogleCodeExporter commented 9 years ago
Thanks,

It works with 
1) of(new PrintStream(System.out))
or
2) of(System.out,PrintStream.class)

though, so that is fine.

Thanks
Georgios

Original comment by georgiad...@googlemail.com on 26 Aug 2009 at 3:29