Affected version
4.1.0-SNAPSHOT (master)
Bug description
In impl/maven-impl/src/main/java/org/apache/maven/impl/model/DefaultModelValidator.java, the validateProfileId() method is missing a null check before calling validProfileIds.contains(id).
Since validProfileIds is a ConcurrentHashMap.newKeySet() (which doesn't allow null keys), passing a null profile ID will throw a NullPointerException instead of a proper validation error.
Inconsistency:
The same file has two similar validation methods with inconsistent null handling:
// Line ~1743 - HAS null check (correct)
private boolean validateCoordinateId(..., String id, ...) {
if (id != null && validCoordinatesIds.contains(id)) {
return true;
}
// ...
}
// Line ~1794 - MISSING null check (bug)
private boolean validateProfileId(..., String id, ...) {
if (validProfileIds.contains(id)) { // Will throw NPE if id is null
return true;
}
// ...
}
Expected behavior
validateProfileId() should handle null IDs gracefully by either:
- Adding a null check like
validateCoordinateId() does: if (id != null && validProfileIds.contains(id))
- Or letting the subsequent validation report the proper error message
Steps to reproduce
- Create a POM with a profile that has a null/missing ID
- Run validation with Maven 4
- Observe NPE instead of proper validation error
Proposed fix
// Change from:
if (validProfileIds.contains(id)) {
// To:
if (id != null && validProfileIds.contains(id)) {
This makes it consistent with validateCoordinateId() and the compat module fix in #11739.
Discovered during code review of #11739
Affected version
4.1.0-SNAPSHOT (master)
Bug description
In
impl/maven-impl/src/main/java/org/apache/maven/impl/model/DefaultModelValidator.java, thevalidateProfileId()method is missing a null check before callingvalidProfileIds.contains(id).Since
validProfileIdsis aConcurrentHashMap.newKeySet()(which doesn't allow null keys), passing a null profile ID will throw aNullPointerExceptioninstead of a proper validation error.Inconsistency:
The same file has two similar validation methods with inconsistent null handling:
Expected behavior
validateProfileId()should handle null IDs gracefully by either:validateCoordinateId()does:if (id != null && validProfileIds.contains(id))Steps to reproduce
Proposed fix
This makes it consistent with
validateCoordinateId()and the compat module fix in #11739.Discovered during code review of #11739