[ 
https://issues.apache.org/jira/browse/MNG-6094?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

A. Di Matteo updated MNG-6094:
------------------------------
    Description: 
Based on the following profile:

{code}
<profile>
    <id>test-profile</id>
    <activation>
        <property>
            <name>something</name>
            <value>!a</value>
        </property>
    </activation>
    ...
</profile>
{code}

And not setting the something property, the profile is always active (by 
default). This is in contradiction with the official Maven profile 
documentation on the !true value example:
{quote}
> The following profile will be activated when the system property "debug" is 
> defined with a value which is not "true".
{quote}
A bug or misleading documentation?

If the mechanism is still implemented by the SystemPropertyProfileActivator, 
deprecated but not documented by which componenet it was replaced, if already 
replaced, then the (potential) bug is confirmed by the following shortened code:

ActivationProperty property = activation.getProperty();
{code}
if ( property != null ) {
    String name = property.getName();
    boolean reverseName = false;

    String sysValue = properties.getProperty( name );

    String propValue = property.getValue();
    if ( StringUtils.isNotEmpty( propValue ) ) {
        boolean reverseValue = false;
        if ( propValue.startsWith( "!" ) ) {
            reverseValue = true;
            propValue = propValue.substring( 1 );
        }

        // we have a value, so it has to match the system value...
        boolean result = propValue.equals( sysValue );

        if ( reverseValue ) {
            return !result;
        }
        else {
            return result;
        }
    }
}
{code}
The issue is: the sysValue real property value by the defined name is not taken 
into account, it will be null in this specific case. However, its check on 
equals will return false, but then the further check on reverseValue would turn 
it to true, regardless of the existence of the name property and effectively 
activating the profile in this case.

Full description at:
http://stackoverflow.com/q/39632024/5606016

  was:
Based on the following profile:

{code}
<profile>
    <id>test-profile</id>
    <activation>
        <property>
            <name>something</name>
            <value>!a</value>
        </property>
    </activation>
    ...
</profile>
{code}

And not setting the something property, the profile is always active (by 
default). This is in contradiction with the official Maven profile 
documentation on the !true value example:

> The following profile will be activated when the system property "debug" is 
> defined with a value which is not "true".

A bug or misleading documentation?

If the mechanism is still implemented by the SystemPropertyProfileActivator, 
deprecated but not documented by which componenet it was replaced, if already 
replaced, then the (potential) bug is confirmed by the following shortened code:

ActivationProperty property = activation.getProperty();
{code}
if ( property != null ) {
    String name = property.getName();
    boolean reverseName = false;

    String sysValue = properties.getProperty( name );

    String propValue = property.getValue();
    if ( StringUtils.isNotEmpty( propValue ) ) {
        boolean reverseValue = false;
        if ( propValue.startsWith( "!" ) ) {
            reverseValue = true;
            propValue = propValue.substring( 1 );
        }

        // we have a value, so it has to match the system value...
        boolean result = propValue.equals( sysValue );

        if ( reverseValue ) {
            return !result;
        }
        else {
            return result;
        }
    }
}
{code}
The issue is: the sysValue real property value by the defined name is not taken 
into account, it will be null in this specific case. However, its check on 
equals will return false, but then the further check on reverseValue would turn 
it to true, regardless of the existence of the name property and effectively 
activating the profile in this case.

Full description at:
http://stackoverflow.com/q/39632024/5606016


> Maven Profile activation (via property) bug (or misleading doc): profile 
> active even if property doesn't exist
> --------------------------------------------------------------------------------------------------------------
>
>                 Key: MNG-6094
>                 URL: https://issues.apache.org/jira/browse/MNG-6094
>             Project: Maven
>          Issue Type: Bug
>          Components: core
>    Affects Versions: 3.3.9
>         Environment: Windows 7
>            Reporter: A. Di Matteo
>
> Based on the following profile:
> {code}
> <profile>
>     <id>test-profile</id>
>     <activation>
>         <property>
>             <name>something</name>
>             <value>!a</value>
>         </property>
>     </activation>
>     ...
> </profile>
> {code}
> And not setting the something property, the profile is always active (by 
> default). This is in contradiction with the official Maven profile 
> documentation on the !true value example:
> {quote}
> > The following profile will be activated when the system property "debug" is 
> > defined with a value which is not "true".
> {quote}
> A bug or misleading documentation?
> If the mechanism is still implemented by the SystemPropertyProfileActivator, 
> deprecated but not documented by which componenet it was replaced, if already 
> replaced, then the (potential) bug is confirmed by the following shortened 
> code:
> ActivationProperty property = activation.getProperty();
> {code}
> if ( property != null ) {
>     String name = property.getName();
>     boolean reverseName = false;
>     String sysValue = properties.getProperty( name );
>     String propValue = property.getValue();
>     if ( StringUtils.isNotEmpty( propValue ) ) {
>         boolean reverseValue = false;
>         if ( propValue.startsWith( "!" ) ) {
>             reverseValue = true;
>             propValue = propValue.substring( 1 );
>         }
>         // we have a value, so it has to match the system value...
>         boolean result = propValue.equals( sysValue );
>         if ( reverseValue ) {
>             return !result;
>         }
>         else {
>             return result;
>         }
>     }
> }
> {code}
> The issue is: the sysValue real property value by the defined name is not 
> taken into account, it will be null in this specific case. However, its check 
> on equals will return false, but then the further check on reverseValue would 
> turn it to true, regardless of the existence of the name property and 
> effectively activating the profile in this case.
> Full description at:
> http://stackoverflow.com/q/39632024/5606016



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to