You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@polygene.apache.org by Niclas Hedhman <ni...@hedhman.org> on 2015/11/08 05:35:38 UTC

Bug in @This injections??

I think that "Private @This" doesn't work for Constructor injections at the
moment.

Not sure if that is because it can't be done, or because the implementation
is lacking the feature.

Looking at the ThisInjectionProviderFactory, I can't figure out how this is
supposed to work at all. And if anyone has interest, please enlighten me of
what we ned to do to support this properly. The previous decorator-feature
I mention, depends on this :-(

Cheers
-- 
Niclas Hedhman, Software Developer
http://zest.apache.org - New Energy for Java

Re: Bug in @This injections??

Posted by Paul Merlin <pa...@nosphere.org>.
Niclas Hedhman a écrit :
> I don't know what you mean by "no luck". Is it, "it works as expected" or
> "it doesn't work as Niclas claims" ?
>
> @Mixins(AbcMixin.class)
> public interface Abc extends TransientComposite {
>
> }
>
> public interface Def
> {
>     Property<String> def();
> }
>
>
> public class AbcMixin
>     implements Abc
> {
>     public AbcMixin( @This Def privateMixin )  // a Def instance is not
> given
>     {
>     }
> }
>
> but if I add Def to the Abc,
>
> public interface Abc extends Def, TransientComposite{}
>
> then there is a value in the constructor.
>
>
> If you had problem understanding what *I* meant, then I hope this is
> clearer.
My "no luck" was in the middle between "it works as expected" and "I'm
not sure what Niclas said" :-)

Tried with your code and it fails with:

Caused by: java.lang.ArrayIndexOutOfBoundsException: 1
	at org.apache.zest.runtime.composite.ConstructorsModel.newConstructorModel(ConstructorsModel.java:130)

 

Kent Sølvsten a écrit :
> It looks like constructor injection *sometimes* works, depending on the
> details.
>
> I made a few experiments, and in some cases it "works" - but a package
> protected constructor or the mixin declared as a non-static inner class
> are at least 2 of the cases giving problems.
> There may be more.
>
> @Niclas: Can you push your concrete testcase to git (possibly ignored) -
> so we are sure we are not comparing apples n' oranges?

I do not have time to push this forward today but the code above exhibit
some issue. We need to wrap up the details and add coverage.

Jacoco reports could help here.
https://builds.apache.org/job/Zest(JavaEdition)-develop-java8-check/ws/build/reports/coverage/index.html

/Paul


Re: Bug in @This injections??

Posted by Kent Sølvsten <ke...@gmail.com>.
It looks like constructor injection *sometimes* works, depending on the
details.

I made a few experiments, and in some cases it "works" - but a package
protected constructor or the mixin declared as a non-static inner class
are at least 2 of the cases giving problems.
There may be more.

@Niclas: Can you push your concrete testcase to git (possibly ignored) -
so we are sure we are not comparing apples n' oranges?

/Kent



Den 17-11-2015 kl. 01:06 skrev Niclas Hedhman:
> I don't know what you mean by "no luck". Is it, "it works as expected" or
> "it doesn't work as Niclas claims" ?
>
> @Mixins(AbcMixin.class)
> public interface Abc extends TransientComposite {
>
> }
>
> public interface Def
> {
>     Property<String> def();
> }
>
>
> public class AbcMixin
>     implements Abc
> {
>     public AbcMixin( @This Def privateMixin )  // a Def instance is not
> given
>     {
>     }
> }
>
> but if I add Def to the Abc,
>
> public interface Abc extends Def, TransientComposite{}
>
> then there is a value in the constructor.
>
>
> If you had problem understanding what *I* meant, then I hope this is
> clearer.
>
> Cheers
> Niclas
>
> On Mon, Nov 16, 2015 at 11:24 PM, Paul Merlin <pa...@nosphere.org> wrote:
>
>> Hey,
>>
>> Catching up ...
>>
>> Niclas Hedhman a écrit :
>>> I think that "Private @This" doesn't work for Constructor injections at
>> the
>>> moment.
>>>
>>> Not sure if that is because it can't be done, or because the
>> implementation
>>> is lacking the feature.
>>>
>>> Looking at the ThisInjectionProviderFactory, I can't figure out how this
>> is
>>> supposed to work at all. And if anyone has interest, please enlighten me
>> of
>>> what we ned to do to support this properly. The previous
>> decorator-feature
>>> I mention, depends on this :-(
>> Niclas Hedhman a écrit :
>>> So, for @This injection in fields, the type is somehow added to the
>>> Composite, but when it is injected in the Constructor, it seems to only
>>> take the public  Composite type interfaces...
>> I tried to understand/reproduce the issue but couldn't.
>> Also added some tests in ConstructorInjectionOfThisTest and
>> PrivateMixinTest by the way, with no luck. The latter existing test was
>> wrong as under-test Work fragment was declared as a *public* mixin.
>>
>> /Paul
>>
>>
>


Re: Bug in @This injections??

Posted by Niclas Hedhman <ni...@hedhman.org>.
I don't know what you mean by "no luck". Is it, "it works as expected" or
"it doesn't work as Niclas claims" ?

@Mixins(AbcMixin.class)
public interface Abc extends TransientComposite {

}

public interface Def
{
    Property<String> def();
}


public class AbcMixin
    implements Abc
{
    public AbcMixin( @This Def privateMixin )  // a Def instance is not
given
    {
    }
}

but if I add Def to the Abc,

public interface Abc extends Def, TransientComposite{}

then there is a value in the constructor.


If you had problem understanding what *I* meant, then I hope this is
clearer.

Cheers
Niclas

On Mon, Nov 16, 2015 at 11:24 PM, Paul Merlin <pa...@nosphere.org> wrote:

> Hey,
>
> Catching up ...
>
> Niclas Hedhman a écrit :
> > I think that "Private @This" doesn't work for Constructor injections at
> the
> > moment.
> >
> > Not sure if that is because it can't be done, or because the
> implementation
> > is lacking the feature.
> >
> > Looking at the ThisInjectionProviderFactory, I can't figure out how this
> is
> > supposed to work at all. And if anyone has interest, please enlighten me
> of
> > what we ned to do to support this properly. The previous
> decorator-feature
> > I mention, depends on this :-(
>
> Niclas Hedhman a écrit :
> > So, for @This injection in fields, the type is somehow added to the
> > Composite, but when it is injected in the Constructor, it seems to only
> > take the public  Composite type interfaces...
>
> I tried to understand/reproduce the issue but couldn't.
> Also added some tests in ConstructorInjectionOfThisTest and
> PrivateMixinTest by the way, with no luck. The latter existing test was
> wrong as under-test Work fragment was declared as a *public* mixin.
>
> /Paul
>
>


-- 
Niclas Hedhman, Software Developer
http://zest.apache.org - New Energy for Java

Re: Bug in @This injections??

Posted by Paul Merlin <pa...@nosphere.org>.
Hey,

Catching up ...

Niclas Hedhman a écrit :
> I think that "Private @This" doesn't work for Constructor injections at the
> moment.
>
> Not sure if that is because it can't be done, or because the implementation
> is lacking the feature.
>
> Looking at the ThisInjectionProviderFactory, I can't figure out how this is
> supposed to work at all. And if anyone has interest, please enlighten me of
> what we ned to do to support this properly. The previous decorator-feature
> I mention, depends on this :-(

Niclas Hedhman a écrit :
> So, for @This injection in fields, the type is somehow added to the
> Composite, but when it is injected in the Constructor, it seems to only
> take the public  Composite type interfaces...
 
I tried to understand/reproduce the issue but couldn't.
Also added some tests in ConstructorInjectionOfThisTest and
PrivateMixinTest by the way, with no luck. The latter existing test was
wrong as under-test Work fragment was declared as a *public* mixin.

/Paul