Yes, I agree this should be an error - certainly not at debug...

On 18 Jul 2010, at 17:55, Marius Bogoevici wrote:

> 
> On 2010-07-18, at 9:04 AM, Pete Muir wrote:
> 
>> Whatever, this is a poor error message!
>> 
> 
> The error message is correct for situations when the interceptor has no 
> bindings - which is a violation of the spec. 
> 
> In this scenario, we're hitting an ambiguity in the specification: the only 
> thing it says about bindings is that they can have as target only types 
> and/or methods, but doesn't say what happens when this provision is violated. 
> 
> In this case we can have a few options: 
> a) treat the offending annotation as "not a binding" and issue a warning (the 
> current logging level is DEBUG, but should be WARN). What happens is that the 
> annotation is effectively ignored as an interceptor binding. 
> b) throw a deployment error complaining about the binding being invalid - 
> trouble is, that this is uncalled for by the specification;
> c) ignore the fact that the binding has extra targets;
> 
> a) is more lenient, but can also be more confusing. We can 'fix' the error 
> message by explaining that the issue may be caused by an invalid 
> InterceptionBinding, but this will still be a problem if we have *two* 
> bindings,  of which one is valid - no error message is shown, but the 
> behaviour will not be the one expected. 
> 
> c) is more lenient too, but allowing to place a binding on something else 
> than a method or type is plainly wrong.
> 
> So, unless there are strong objections to it, I will switch to b), since 
> there's no good way of making clear that the binding annotation is ignored 
> (the warning is the best thing that we can do, but it's easy to loose track 
> of it). Also, this is effectively an error, since it's an attempt to use the 
> CDI API in ways that are not intended to be supported. I also think that we 
> should capture this a spec revision.
> 
> 
> 
>> Marcin, could you file an issue in WELD please?
>> 
>> On 18 Jul 2010, at 03:03, Marius Bogoevici wrote:
>> 
>>> Hi Marcin,
>>> 
>>> Only annotations with @Target({ElementType.METHOD, ElementType.TYPE}) or 
>>> @Target({ElementType.TYPE}) can be interceptor bindings (chapter 1 of the 
>>> spec).
>>> 
>>> CDI interceptors cannot be defined for constructors per se (so there's no 
>>> around-constructor semantics), but you can have a @PostConstruct method on 
>>> a @Target({ElementType.TYPE}) interceptor, which effectively executes after 
>>> the instance has been created and CDI-injected.
>>> 
>>> Hope this helps,
>>> Marius
>>> 
>>> On 2010-07-17, at 5:36 PM, Marcin Zajączkowski wrote:
>>> 
>>>> Hi,
>>>> 
>>>> 
>>>> I'm trying to write mocked unit tests for my interceptor using
>>>> mechanisms given by AbstractWeldTest and jboss-test-harness package.
>>>> 
>>>> My test class extends AbstractWeldTest, had Artifact and WebBeans
>>>> (pointing to beans.xml with my interceptor defined) annotations.
>>>> 
>>>> My interceptor seems normal for me:
>>>> @Target({ElementType.METHOD, ElementType.CONSTRUCTOR, ElementType.TYPE})
>>>> @Retention(RetentionPolicy.RUNTIME)
>>>> @InterceptorBinding
>>>> public @interface Perf4jProfiled {
>>>> }
>>>> 
>>>> When I run a very simple test, I've got:
>>>> 23:06:53.505 [main] DEBUG org.jboss.weld.Reflection - WELD-000602
>>>> interface net.sf.perf4cdi.api.Perf4jProfiled is not declared
>>>> @Target(TYPE, METHOD) or @Target(TYPE)
>>>> org.jboss.weld.exceptions.DeploymentException: WELD-000069 An
>>>> interceptor must have at least one binding, but
>>>> net.sf.perf4cdi.Perf4jProfiledInterceptor has none
>>>>    at org.jboss.weld.bean.InterceptorImpl.<init>(InterceptorImpl.java:71)
>>>>    at org.jboss.weld.bean.InterceptorImpl.of(InterceptorImpl.java:55)
>>>>    at
>>>> org.jboss.weld.bootstrap.AbstractBeanDeployer.createInterceptor(AbstractBeanDeployer.java:255)
>>>>    at 
>>>> org.jboss.weld.bootstrap.BeanDeployer.createBeans(BeanDeployer.java:106)
>>>>    at
>>>> org.jboss.weld.bootstrap.BeanDeployment.deployBeans(BeanDeployment.java:151)
>>>>    at
>>>> org.jboss.weld.bootstrap.WeldBootstrap.deployBeans(WeldBootstrap.java:377)
>>>>    at
>>>> org.jboss.weld.mock.MockServletLifecycle.beginApplication(MockServletLifecycle.java:121)
>>>>    at 
>>>> org.jboss.weld.mock.TestContainer.startContainer(TestContainer.java:85)
>>>>    at
>>>> org.jboss.weld.test.harness.AbstractStandaloneContainersImpl.deploy(AbstractStandaloneContainersImpl.java:40)
>>>>    at 
>>>> org.jboss.testharness.AbstractTest.deployArtifact(AbstractTest.java:103)
>>>>    at org.jboss.testharness.AbstractTest.beforeClass(AbstractTest.java:206)
>>>>    at
>>>> org.jboss.weld.test.AbstractWeldTest.beforeClass(AbstractWeldTest.java:57)
>>>> 
>>>> 
>>>> When I remove CONSTRUCTOR it works better (there is another problem, but
>>>> not related I have to debug it).
>>>> 
>>>> I would like to ask if this is a limitation of CDI that an interceptor
>>>> cannot be put on constructor?
>>>> 
>>>> 
>>>> Regards
>>>> Marcin
>>>> 
>>>> _______________________________________________
>>>> weld-dev mailing list
>>>> [email protected]
>>>> https://lists.jboss.org/mailman/listinfo/weld-dev
>>> 
>>> 
>>> _______________________________________________
>>> weld-dev mailing list
>>> [email protected]
>>> https://lists.jboss.org/mailman/listinfo/weld-dev
>> 
> 


_______________________________________________
weld-dev mailing list
[email protected]
https://lists.jboss.org/mailman/listinfo/weld-dev

Reply via email to