gnodet commented on code in PR #11186:
URL: https://github.com/apache/maven/pull/11186#discussion_r3646644394
##########
impl/maven-impl/src/main/java/org/apache/maven/impl/DefaultModelXmlFactory.java:
##########
@@ -52,17 +52,19 @@ public class DefaultModelXmlFactory implements
ModelXmlFactory {
public Model read(@Nonnull XmlReaderRequest request) throws
XmlReaderException {
requireNonNull(request, "request");
Model model = doRead(request);
- if (isModelVersionGreaterThan400(model)
- &&
!model.getNamespaceUri().startsWith("http://maven.apache.org/POM/")) {
- throw new XmlReaderException(
- "Invalid namespace '" + model.getNamespaceUri() + "' for
model version " + model.getModelVersion(),
- null,
- null);
+ if (isModelVersionGreaterOrEqualsThan400(model)) {
+ String ns = model.getNamespaceUri();
+ if (ns.length() > 0 &&
!model.getNamespaceUri().startsWith("http://maven.apache.org/POM/")) {
+ throw new XmlReaderException(
Review Comment:
Bug: The `ns.length() > 0` guard short-circuits the namespace check for ALL
model versions ≥ 4.0.0 when namespace is empty — including 4.1.0+. On master, a
4.1.0 POM with empty namespace correctly throws `XmlReaderException` (because
`"".startsWith("http://maven.apache.org/POM/")` is false). With this change,
empty namespaces are silently accepted for 4.1.0+.
The empty-namespace exemption should only apply to 4.0.0, not to 4.1.0+.
Consider separating the logic:
```java
if (isModelVersionGreaterOrEqualsThan400(model)) {
String ns = model.getNamespaceUri();
boolean emptyNamespace = ns.isEmpty();
if (!emptyNamespace && !ns.startsWith("http://maven.apache.org/POM/")) {
throw new XmlReaderException(...);
}
if (emptyNamespace && isModelVersionGreaterThan400(model)) {
throw new XmlReaderException("Missing namespace for model version "
+ model.getModelVersion() + "...", null, null);
}
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]