I would say this has an even bigger "ugly" picture.
This is where Java + collections got it completely wrong,
since passing collections around doesn't say anything wrt (im)mutability.
Hence one must always presume things are immutable,
while in fact the intention was actually to be mutable,
and only javadoc can help you there, and not compiler.
CDI is unfortunately no exception here.
On Mar 21, 2011, at 12:18 PM, Pete Muir wrote:
As Mark says, the spec doesn't say whether they are mutable or
immutable, therefore it's an implementation choice whether to make them mutable or
immutable. In order for your extension to be portable you'll need to assume they are
immutable, as then it will work in either case. There are many cases where behaviour is
intentionally undefined so that it is an implementors choice. This is one for the Java EE
docs I guess.
We can add something to the javadoc like "There is no requirement for these sets to
be mutable" but I don't think we should require them to be either.
On 18 Mar 2011, at 09:54, Mark Struberg wrote:
> Hmm, I wouldn't argue that way.
> The spec _and_ the JavaDocs just say "Returns: all annotations of the program
element, or an empty set if no annotations are present"
> There is a hint in the spec which might underline your interpretation: "Any
observer of this event is permitted to _wrap_ and/or replace the AnnotatedType". But
that sentence doesn't rule out the simple modification.
> If they are all immutable, then we should express this explicitly in the CDI-1.1
> --- On Fri, 3/18/11, Stuart Douglas <stuart.w.douglas(a)gmail.com> wrote:
>> From: Stuart Douglas <stuart.w.douglas(a)gmail.com>
>> Subject: Re: [weld-dev] are AnnotatedType and Co immutable?
>> To: "Mark Struberg" <struberg(a)yahoo.de>
>> Cc: "weld-dev(a)lists.jboss.org" <weld-dev(a)lists.jboss.org>
>> Date: Friday, March 18, 2011, 9:35 AM
>> In weld the sets are immutable (or
>> defensive copies, can't remember).
>> I don't think that just because the spec does not mention
>> immutability that you could expect to modify internal state
>> of the annotated type through the set.
>> Sent from my iPhone
>> On 18/03/2011, at 20:24, Mark Struberg <struberg(a)yahoo.de>
>>> Hi folks!
>>> If I pat(@Observes ProcessAnnotatedType
>> annotatedType), is it allowed to simply modify the Sets?
>>> E.g. call
>>> annotatedType.getAnnotations().add(myOwnAnnotation) ?
>>> The spec imo doesn't mention that those Sets are
>> immutable, so it should work. It works in OWB at least, but
>> what about Weld and CanDI?
>>> txs and LieGrue,
>>> weld-dev mailing list
> weld-dev mailing list
weld-dev mailing list