Uploaded image for project: 'Maven Project Web Site'
  1. Maven Project Web Site
  2. MNGSITE-293

Maven Profile activation (via property) bug (or misleading doc): profile active even if property doesn't exist

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • Windows 7

    Description

      Based on the following profile:

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

      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();

      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;
              }
          }
      }
      

      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

      Attachments

        Activity

          People

            gboue Guillaume Boué
            antdim A. Di Matteo
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: