You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@karaf.apache.org by Setya <js...@gmail.com> on 2017/03/31 17:09:03 UTC

Blueprint fails instantiating bean with generic constructor

Hi all,

Aries Blueprint fails to instantiate bean with the following constructors:

public AggregateAnnotationCommandHandler(Class<T> aggregateType,
Repository<T> repository)
{
}

It seems to have problems with the second argument since it contains generic
parameter.

While it successfully instantiates the following bean:

public EventSourcingRepository(AggregateFactory<T> aggregateFactory,
EventStore eventStore)
{
}

I'm using Apache Karaf 4.0.8.

Any insight would be greatly appreciated.

Thanks & Regards,
Setya



--
View this message in context: http://karaf.922171.n3.nabble.com/Blueprint-fails-instantiating-bean-with-generic-constructor-tp4049986.html
Sent from the Karaf - User mailing list archive at Nabble.com.

RE: Blueprint fails instantiating bean with generic constructor

Posted by Setya <js...@gmail.com>.
Hi JP,

Thanks. I've voted it.

Regards,
Setya



--
View this message in context: http://karaf.922171.n3.nabble.com/Blueprint-fails-instantiating-bean-with-generic-constructor-tp4049986p4050004.html
Sent from the Karaf - User mailing list archive at Nabble.com.

Re: Blueprint fails instantiating bean with generic constructor

Posted by Guillaume Nodet <gn...@apache.org>.
2017-04-03 17:03 GMT+02:00 CLEMENT Jean-Philippe <
jean-philippe.clement@fr.thalesgroup.com>:

> I understand your point and you’re right, it’s better to test things early
> than let the system crash later on. To go further I guess the Blueprint
> spec would have to be enhanced to fully support generics, for instance to
> be able to instantiate an ArrayList<String> bean, to expose and retrieve
> services with generics signature etc.
>

That's what I did to some degree with my ARIES-960 branch:
  https://github.com/gnodet/aries/tree/ARIES-960/blueprint/blueprint-core

That's why I'd like some people to look at it and see if their actual use
case works.
From that point:
  * they work, and that's great
  * they don't work and they should, and I'll work on fixing those
  * they don't work because they require ARIES-1633 which I don't have the
time to implement in the short term
In the third case, I could look at adding a flag...


>
>
> That said, a fallback strategy could also be welcome in the meantime. And
> it would be more efficient than letting the system try to convert, fail,
> then finally use the custom “erasure converter” defined in the Blueprint.
>
>
>
> Would it be possible to get a nice generics defeat flag?
>

Please provide a test case for my ARIES-960 branch which falls into the
third category above.


>
>
> Regards,
>
> JP
>
>
>
> *De :* Guillaume Nodet [mailto:gnodet@apache.org]
> *Envoyé :* lundi 3 avril 2017 16:30
>
> *À :* user
> *Objet :* Re: Blueprint fails instantiating bean with generic constructor
>
>
>
> I still am not comfortable allowing casting List<String> to List<Integer>
> as we perfectly know what will happen.
>
> Blueprint is not a compiler, but if you look at CDI, those kind of
> problems have been handled correctly for example, and CDI is not a compiler
> either, but both blueprint and CDI are dependency  injection framework, so
> there's no technical reason to not be able to support the use cases
> correctly, instead of allowing ClassCastException at a later time.
>
>
>
> 2017-04-03 15:46 GMT+02:00 CLEMENT Jean-Philippe <
> jean-philippe.clement@fr.thalesgroup.com>:
>
> Hi Guillaume,
>
>
>
> As already discussed, Blueprint is not a compiler but a runtime library.
> Once compiled there is no more generics as Java is a type erasure language.
> Moreover, I’m not too sure how Blueprint may handle injection with things
> like <S> S getSomething() where in java you can write myinstance.<Boolean>
> getSomething().
>
>
>
> I still do have issues with injection and generics, so a global flag to
> defeat Blueprint checking would be greatly appreciated :)
>
>
>
> JP
>
>
>
> *De :* Guillaume Nodet [mailto:gnodet@apache.org]
> *Envoyé :* lundi 3 avril 2017 14:31
> *À :* user
> *Objet :* Re: Blueprint fails instantiating bean with generic constructor
>
>
>
>  There are 2 different issues.
>
> One is type erasure, i.e. allow the invocation of a method taking a
> List<String> with a List<Integer> for example.  That's ARIES-1607, and I
> really think that's a bad idea, unless someone show me a good example where
> it makes sense.  At least by default (well, it's against the blueprint spec
> anyway).  A flag to turn on such a behavior (on a bean or globally) could
> be an acceptable way, though.
>
>
>
> Another issue is ARIES-960 where the same thing written in java would
> work.  That's a problem of type assignability verification and I'm willing
> to fix those.  I think that's more your use case.  There's a branch I
> created a while ago with some changes.  Could you check if your use case
> works with the code there ?
>
>
>
> In all cases, a workaround is always to provide a custom blueprint
> converter, as this would allow converting whatever you want to whatever is
> needed.
>
>
>
>
>
>
>
> 2017-04-03 11:23 GMT+02:00 CLEMENT Jean-Philippe <
> jean-philippe.clement@fr.thalesgroup.com>:
>
> Hi Setya,
>
> It might be related to an issue I opened last year:
> https://issues.apache.org/jira/browse/ARIES-1607
>
> At that time I was told to add a custom converter as a workaround. No
> update on the Jira since then; maybe you may vote for it :)
>
> Regards,
> JP
>
> -----Message d'origine-----
> De : Setya [mailto:jsetya@gmail.com]
> Envoyé : vendredi 31 mars 2017 19:09
> À : user@karaf.apache.org
> Objet : Blueprint fails instantiating bean with generic constructor
>
>
> Hi all,
>
> Aries Blueprint fails to instantiate bean with the following constructors:
>
> public AggregateAnnotationCommandHandler(Class<T> aggregateType,
> Repository<T> repository) { }
>
> It seems to have problems with the second argument since it contains
> generic parameter.
>
> While it successfully instantiates the following bean:
>
> public EventSourcingRepository(AggregateFactory<T> aggregateFactory,
> EventStore eventStore) { }
>
> I'm using Apache Karaf 4.0.8.
>
> Any insight would be greatly appreciated.
>
> Thanks & Regards,
> Setya
>
>
>
> --
> View this message in context: http://karaf.922171.n3.nabble.
> com/Blueprint-fails-instantiating-bean-with-generic-constructor-tp4049986.
> html
> Sent from the Karaf - User mailing list archive at Nabble.com.
>
>
>
>
>
> --
>
> ------------------------
> Guillaume Nodet
>
>
>
>
>
>
>
> --
>
> ------------------------
> Guillaume Nodet
>
>
>



-- 
------------------------
Guillaume Nodet

RE: Blueprint fails instantiating bean with generic constructor

Posted by CLEMENT Jean-Philippe <je...@fr.thalesgroup.com>.
I understand your point and you’re right, it’s better to test things early than let the system crash later on. To go further I guess the Blueprint spec would have to be enhanced to fully support generics, for instance to be able to instantiate an ArrayList<String> bean, to expose and retrieve services with generics signature etc.

That said, a fallback strategy could also be welcome in the meantime. And it would be more efficient than letting the system try to convert, fail, then finally use the custom “erasure converter” defined in the Blueprint.

Would it be possible to get a nice generics defeat flag?

Regards,
JP

De : Guillaume Nodet [mailto:gnodet@apache.org]
Envoyé : lundi 3 avril 2017 16:30
À : user
Objet : Re: Blueprint fails instantiating bean with generic constructor

I still am not comfortable allowing casting List<String> to List<Integer> as we perfectly know what will happen.
Blueprint is not a compiler, but if you look at CDI, those kind of problems have been handled correctly for example, and CDI is not a compiler either, but both blueprint and CDI are dependency  injection framework, so there's no technical reason to not be able to support the use cases correctly, instead of allowing ClassCastException at a later time.

2017-04-03 15:46 GMT+02:00 CLEMENT Jean-Philippe <je...@fr.thalesgroup.com>>:
Hi Guillaume,

As already discussed, Blueprint is not a compiler but a runtime library. Once compiled there is no more generics as Java is a type erasure language. Moreover, I’m not too sure how Blueprint may handle injection with things like <S> S getSomething() where in java you can write myinstance.<Boolean> getSomething().

I still do have issues with injection and generics, so a global flag to defeat Blueprint checking would be greatly appreciated :)

JP

De : Guillaume Nodet [mailto:gnodet@apache.org<ma...@apache.org>]
Envoyé : lundi 3 avril 2017 14:31
À : user
Objet : Re: Blueprint fails instantiating bean with generic constructor

 There are 2 different issues.
One is type erasure, i.e. allow the invocation of a method taking a List<String> with a List<Integer> for example.  That's ARIES-1607, and I really think that's a bad idea, unless someone show me a good example where it makes sense.  At least by default (well, it's against the blueprint spec anyway).  A flag to turn on such a behavior (on a bean or globally) could be an acceptable way, though.

Another issue is ARIES-960 where the same thing written in java would work.  That's a problem of type assignability verification and I'm willing to fix those.  I think that's more your use case.  There's a branch I created a while ago with some changes.  Could you check if your use case works with the code there ?

In all cases, a workaround is always to provide a custom blueprint converter, as this would allow converting whatever you want to whatever is needed.



2017-04-03 11:23 GMT+02:00 CLEMENT Jean-Philippe <je...@fr.thalesgroup.com>>:
Hi Setya,

It might be related to an issue I opened last year: https://issues.apache.org/jira/browse/ARIES-1607

At that time I was told to add a custom converter as a workaround. No update on the Jira since then; maybe you may vote for it :)

Regards,
JP

-----Message d'origine-----
De : Setya [mailto:jsetya@gmail.com<ma...@gmail.com>]
Envoyé : vendredi 31 mars 2017 19:09
À : user@karaf.apache.org<ma...@karaf.apache.org>
Objet : Blueprint fails instantiating bean with generic constructor

Hi all,

Aries Blueprint fails to instantiate bean with the following constructors:

public AggregateAnnotationCommandHandler(Class<T> aggregateType, Repository<T> repository) { }

It seems to have problems with the second argument since it contains generic parameter.

While it successfully instantiates the following bean:

public EventSourcingRepository(AggregateFactory<T> aggregateFactory, EventStore eventStore) { }

I'm using Apache Karaf 4.0.8.

Any insight would be greatly appreciated.

Thanks & Regards,
Setya



--
View this message in context: http://karaf.922171.n3.nabble.com/Blueprint-fails-instantiating-bean-with-generic-constructor-tp4049986.html
Sent from the Karaf - User mailing list archive at Nabble.com.



--
------------------------
Guillaume Nodet




--
------------------------
Guillaume Nodet


Re: Blueprint fails instantiating bean with generic constructor

Posted by Guillaume Nodet <gn...@apache.org>.
I still am not comfortable allowing casting List<String> to List<Integer>
as we perfectly know what will happen.
Blueprint is not a compiler, but if you look at CDI, those kind of problems
have been handled correctly for example, and CDI is not a compiler either,
but both blueprint and CDI are dependency  injection framework, so there's
no technical reason to not be able to support the use cases correctly,
instead of allowing ClassCastException at a later time.

2017-04-03 15:46 GMT+02:00 CLEMENT Jean-Philippe <
jean-philippe.clement@fr.thalesgroup.com>:

> Hi Guillaume,
>
>
>
> As already discussed, Blueprint is not a compiler but a runtime library.
> Once compiled there is no more generics as Java is a type erasure language.
> Moreover, I’m not too sure how Blueprint may handle injection with things
> like <S> S getSomething() where in java you can write myinstance.<Boolean>
> getSomething().
>
>
>
> I still do have issues with injection and generics, so a global flag to
> defeat Blueprint checking would be greatly appreciated :)
>
>
>
> JP
>
>
>
> *De :* Guillaume Nodet [mailto:gnodet@apache.org]
> *Envoyé :* lundi 3 avril 2017 14:31
> *À :* user
> *Objet :* Re: Blueprint fails instantiating bean with generic constructor
>
>
>
>  There are 2 different issues.
>
> One is type erasure, i.e. allow the invocation of a method taking a
> List<String> with a List<Integer> for example.  That's ARIES-1607, and I
> really think that's a bad idea, unless someone show me a good example where
> it makes sense.  At least by default (well, it's against the blueprint spec
> anyway).  A flag to turn on such a behavior (on a bean or globally) could
> be an acceptable way, though.
>
>
>
> Another issue is ARIES-960 where the same thing written in java would
> work.  That's a problem of type assignability verification and I'm willing
> to fix those.  I think that's more your use case.  There's a branch I
> created a while ago with some changes.  Could you check if your use case
> works with the code there ?
>
>
>
> In all cases, a workaround is always to provide a custom blueprint
> converter, as this would allow converting whatever you want to whatever is
> needed.
>
>
>
>
>
>
>
> 2017-04-03 11:23 GMT+02:00 CLEMENT Jean-Philippe <
> jean-philippe.clement@fr.thalesgroup.com>:
>
> Hi Setya,
>
> It might be related to an issue I opened last year:
> https://issues.apache.org/jira/browse/ARIES-1607
>
> At that time I was told to add a custom converter as a workaround. No
> update on the Jira since then; maybe you may vote for it :)
>
> Regards,
> JP
>
> -----Message d'origine-----
> De : Setya [mailto:jsetya@gmail.com]
> Envoyé : vendredi 31 mars 2017 19:09
> À : user@karaf.apache.org
> Objet : Blueprint fails instantiating bean with generic constructor
>
>
> Hi all,
>
> Aries Blueprint fails to instantiate bean with the following constructors:
>
> public AggregateAnnotationCommandHandler(Class<T> aggregateType,
> Repository<T> repository) { }
>
> It seems to have problems with the second argument since it contains
> generic parameter.
>
> While it successfully instantiates the following bean:
>
> public EventSourcingRepository(AggregateFactory<T> aggregateFactory,
> EventStore eventStore) { }
>
> I'm using Apache Karaf 4.0.8.
>
> Any insight would be greatly appreciated.
>
> Thanks & Regards,
> Setya
>
>
>
> --
> View this message in context: http://karaf.922171.n3.nabble.
> com/Blueprint-fails-instantiating-bean-with-generic-constructor-tp4049986.
> html
> Sent from the Karaf - User mailing list archive at Nabble.com.
>
>
>
>
>
> --
>
> ------------------------
> Guillaume Nodet
>
>
>



-- 
------------------------
Guillaume Nodet

RE: Blueprint fails instantiating bean with generic constructor

Posted by CLEMENT Jean-Philippe <je...@fr.thalesgroup.com>.
Hi Guillaume,

As already discussed, Blueprint is not a compiler but a runtime library. Once compiled there is no more generics as Java is a type erasure language. Moreover, I’m not too sure how Blueprint may handle injection with things like <S> S getSomething() where in java you can write myinstance.<Boolean> getSomething().

I still do have issues with injection and generics, so a global flag to defeat Blueprint checking would be greatly appreciated :)

JP

De : Guillaume Nodet [mailto:gnodet@apache.org]
Envoyé : lundi 3 avril 2017 14:31
À : user
Objet : Re: Blueprint fails instantiating bean with generic constructor

 There are 2 different issues.
One is type erasure, i.e. allow the invocation of a method taking a List<String> with a List<Integer> for example.  That's ARIES-1607, and I really think that's a bad idea, unless someone show me a good example where it makes sense.  At least by default (well, it's against the blueprint spec anyway).  A flag to turn on such a behavior (on a bean or globally) could be an acceptable way, though.

Another issue is ARIES-960 where the same thing written in java would work.  That's a problem of type assignability verification and I'm willing to fix those.  I think that's more your use case.  There's a branch I created a while ago with some changes.  Could you check if your use case works with the code there ?

In all cases, a workaround is always to provide a custom blueprint converter, as this would allow converting whatever you want to whatever is needed.



2017-04-03 11:23 GMT+02:00 CLEMENT Jean-Philippe <je...@fr.thalesgroup.com>>:
Hi Setya,

It might be related to an issue I opened last year: https://issues.apache.org/jira/browse/ARIES-1607

At that time I was told to add a custom converter as a workaround. No update on the Jira since then; maybe you may vote for it :)

Regards,
JP

-----Message d'origine-----
De : Setya [mailto:jsetya@gmail.com<ma...@gmail.com>]
Envoyé : vendredi 31 mars 2017 19:09
À : user@karaf.apache.org<ma...@karaf.apache.org>
Objet : Blueprint fails instantiating bean with generic constructor

Hi all,

Aries Blueprint fails to instantiate bean with the following constructors:

public AggregateAnnotationCommandHandler(Class<T> aggregateType, Repository<T> repository) { }

It seems to have problems with the second argument since it contains generic parameter.

While it successfully instantiates the following bean:

public EventSourcingRepository(AggregateFactory<T> aggregateFactory, EventStore eventStore) { }

I'm using Apache Karaf 4.0.8.

Any insight would be greatly appreciated.

Thanks & Regards,
Setya



--
View this message in context: http://karaf.922171.n3.nabble.com/Blueprint-fails-instantiating-bean-with-generic-constructor-tp4049986.html
Sent from the Karaf - User mailing list archive at Nabble.com.



--
------------------------
Guillaume Nodet


Re: Blueprint fails instantiating bean with generic constructor

Posted by Guillaume Nodet <gn...@apache.org>.
 There are 2 different issues.
One is type erasure, i.e. allow the invocation of a method taking a
List<String> with a List<Integer> for example.  That's ARIES-1607, and I
really think that's a bad idea, unless someone show me a good example where
it makes sense.  At least by default (well, it's against the blueprint spec
anyway).  A flag to turn on such a behavior (on a bean or globally) could
be an acceptable way, though.

Another issue is ARIES-960 where the same thing written in java would
work.  That's a problem of type assignability verification and I'm willing
to fix those.  I think that's more your use case.  There's a branch I
created a while ago with some changes.  Could you check if your use case
works with the code there ?

In all cases, a workaround is always to provide a custom blueprint
converter, as this would allow converting whatever you want to whatever is
needed.



2017-04-03 11:23 GMT+02:00 CLEMENT Jean-Philippe <
jean-philippe.clement@fr.thalesgroup.com>:

> Hi Setya,
>
> It might be related to an issue I opened last year:
> https://issues.apache.org/jira/browse/ARIES-1607
>
> At that time I was told to add a custom converter as a workaround. No
> update on the Jira since then; maybe you may vote for it :)
>
> Regards,
> JP
>
> -----Message d'origine-----
> De : Setya [mailto:jsetya@gmail.com]
> Envoyé : vendredi 31 mars 2017 19:09
> À : user@karaf.apache.org
> Objet : Blueprint fails instantiating bean with generic constructor
>
> Hi all,
>
> Aries Blueprint fails to instantiate bean with the following constructors:
>
> public AggregateAnnotationCommandHandler(Class<T> aggregateType,
> Repository<T> repository) { }
>
> It seems to have problems with the second argument since it contains
> generic parameter.
>
> While it successfully instantiates the following bean:
>
> public EventSourcingRepository(AggregateFactory<T> aggregateFactory,
> EventStore eventStore) { }
>
> I'm using Apache Karaf 4.0.8.
>
> Any insight would be greatly appreciated.
>
> Thanks & Regards,
> Setya
>
>
>
> --
> View this message in context: http://karaf.922171.n3.nabble.
> com/Blueprint-fails-instantiating-bean-with-generic-constructor-tp4049986.
> html
> Sent from the Karaf - User mailing list archive at Nabble.com.
>



-- 
------------------------
Guillaume Nodet

RE: Blueprint fails instantiating bean with generic constructor

Posted by CLEMENT Jean-Philippe <je...@fr.thalesgroup.com>.
Hi Setya,

It might be related to an issue I opened last year: https://issues.apache.org/jira/browse/ARIES-1607

At that time I was told to add a custom converter as a workaround. No update on the Jira since then; maybe you may vote for it :)

Regards,
JP

-----Message d'origine-----
De : Setya [mailto:jsetya@gmail.com] 
Envoyé : vendredi 31 mars 2017 19:09
À : user@karaf.apache.org
Objet : Blueprint fails instantiating bean with generic constructor

Hi all,

Aries Blueprint fails to instantiate bean with the following constructors:

public AggregateAnnotationCommandHandler(Class<T> aggregateType, Repository<T> repository) { }

It seems to have problems with the second argument since it contains generic parameter.

While it successfully instantiates the following bean:

public EventSourcingRepository(AggregateFactory<T> aggregateFactory, EventStore eventStore) { }

I'm using Apache Karaf 4.0.8.

Any insight would be greatly appreciated.

Thanks & Regards,
Setya



--
View this message in context: http://karaf.922171.n3.nabble.com/Blueprint-fails-instantiating-bean-with-generic-constructor-tp4049986.html
Sent from the Karaf - User mailing list archive at Nabble.com.