Usually I like quizzes, but this one is a bit harsh for a Friday ;).
Since the spec doesn’t say anything about xml validation, I don’t think we can take it
into consideration for container behaviour.
Le 21 oct. 2016 à 15:23, Martin Kouba <mkouba(a)redhat.com> a
écrit :
Hi all,
today I struggled with weird beans.xml parsing problems and I found out
that this part of CDI might deserve some clarification. Below are few
examples. And not all of them have obvious interpretation.
Also note that the spec still contains invalid beans.xml snippets (see
also CDI-449).
Do you mean, there are still invalid snipers after Tomas PR ?
1. empty beans.xml marker file
- spec VALID, bean-discovey-mode="ALL"
- XSD validation not needed
2. <beans/>
- spec VALID, bean-discovey-mode="ALL"
- XSD validation not possible
3. <beans
xmlns="http://java.sun.com/xml/ns/javaee">
- spec VALID, Java EE 6 namespace, ie. CDI 1.0, bean-discovey-mode="ALL"
- XSD validation OK (against beans_1_0.xsd)
4. <beans
xmlns="http://xmlns.jcp.org/xml/ns/javaee">
- spec VALID
- XSD validation ERROR - Java EE 7 namespace, i.e. CDI 1.1+ and
bean-discovey-mode attribute is required
- note that version is defaulted to "1.1" (and e.g. SAXParser fills this
value automatically)
- what's the correct bean-discovey-mode? => I would expect ANNOTATED
because we're in EE 7 and it's the default bean discovery mode
- bean-discovey-mode attribute is required, not defaulted
- current Weld behavior: ALL
As I said in introduction I don’t think we can take xsd into consideration to decide
container behaviour.
So IMO here Weld behaviour is the expected one:
"A bean archive which contains a beans.xml file with no version has a default bean
discovery mode of all"
5. <beans
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
version="1.1">
- spec INVALID, "A bean archive which contains a beans.xml file with
version 1.1 (or later) must specify the bean-discovey-mode attribute.
The default value for the attribute is annotated."
- XSD validation ERROR, bean-discovey-mode attribute is required
- what's the correct bean-discovey-mode? => I would expect ANNOTATED
- current Weld behavior: ALL
IMO, deployment should fail or we should rephrase the spec (backward compatibility?)
6. <beans version="1.1">
- spec INVALID, the same as above
- XSD validation not possible
- what's the correct bean-discovey-mode? => I would expect ANNOTATED
- current Weld behavior: ALL
Same as 5 for me
7. <beans version="1.1" bean-discovery-mode="annotated">
- spec VALID, bean-discovey-mode="ANNOTATED"
- XSD validation not possible
NP
8. <beans version="1.1"
bean-discovery-mode="all"
xmlns="http://xmlns.jcp.org/xml/ns/javaee">
- spec VALID, bean-discovey-mode="ALL"
- XSD VALID
We may consider adding default value for bean-discovey-mode, and maybe
rewording the spec text. But I'm no XML guru so maybe I'm missing something.
Again we don’t have any mention of valid XML file (regarding XSD) in the spec, so there
might be a lot of broken beans.xml file around. Making this straight could break these
apps.
wdyt ?
Thanks,
Martin
Antoine