apache / apache/maven-enforcer

[MENFORCER-363] Unexpected result from requireProperty with regex when the property is not fully resolved

Open
#476 1 comment 0 reactions 0 assignees View on GitHub
bug priority:major
Dominant language
Java
Stars
161
Forks
180
Avg merge
1d 20m
Merged PRs (30d)
8

Description

**[Bertrand Renuart](https://issues.apache.org/jira/secure/ViewProfile.jspa?name=brenuart)** opened **[MENFORCER-363](https://issues.apache.org/jira/browse/MENFORCER-363?redirect=false)** and commented

I was looking for a way to verify a property is defined and is fully resolved. When it cannot resolve a placeholder, Maven usually leave it unchanged. So if property "unknown" is not defined, "\pre-${unknown}\" would not fully resolve and would left asis.

With this in mind, I thought I could use the "requireProperty" with a regex looking for "$" to check if a property is fully resolved or not. 

Consider the following example:

```java

${unknown}
pre${unknown}

maven-enforcer-plugin
3.0.0-M3


enforce



foo
[^$]*


bar
[^$]*


...
```

 

Here is what the execution reports:

```java
[WARNING] Rule 0: org.apache.maven.plugins.enforcer.RequireProperty failed with message:
Property "foo" is required for this build.
```

 

For the first rule, since "foo" refers to an _unknown_ property, I can understand it is "not defined" and that the rule complains about it.

However, I would expect the second rule to fail as well. Let's change its regex to "[0-9]+" to see what happens:

```java
[WARNING] Rule 1: org.apache.maven.plugins.enforcer.RequireProperty failed with message:
Property "bar" evaluates to "prenull".  This does not match the regular expression "[0-9]+"
```

As we can see, the placeholder "${unknown}" has been resolved into "null" - reason why the rule didn't fail initially...

 

IMHO this behaviour is not intuitive since Maven's standard behaviour is to leave placeholders unchanged when they cannot be resolved.

 

 

---

**Affects:** 3.0.0-M3

**Issue Links:**
- [MNG-7194](https://issues.apache.org/jira/browse/MNG-7194) PluginParameterExpressionEvaluator incorrectly interpolates unknown subexpression
(_**"is caused by"**_)

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the RequireProperty rule and reproduce the supplied Maven configuration, comparing unresolved properties such as foo and bar. Review the linked MNG-7194 issue because the report identifies it as the cause. Done means unresolved placeholders are handled consistently with Maven's standard behavior and the reported regex checks produce the expected result.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
build-system
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.