Buggy environment variable substitution - the order should NOT matter!


  1. mmo
    Posts : 140
    Windows 10
       #1

    Buggy environment variable substitution - the order should NOT matter!


    In preparation of an upcoming development project I downloaded and installed the latest Maven version.
    Then - as instructed - I defined me two environment variables:
    Code:
    M2=%M2_HOME%\bin
    M2_HOME=C:\Program Files\Apache Software Foundation\apache-maven-3.6.0
    But for some strange reason the former %-placeholder 'M2' is not processed, i.e. "set" just yields:
    Code:
    M2=%M2_HOME%\bin
    M2_HOME=C:\Program Files\Apache Software Foundation\apache-maven-3.6.0
    It seems that the order in which the env-var dialog stores these variables is important and if a former variable refers to one further down in the alphabetical list, then: bad luck!

    To test that hypothesis I defined me:
    Code:
    TestX=%TestY%\test3
    TestY=%TestZ%\test2
    TestZ=%JAVA_HOME%\test1
    and the result is:
    Code:
    TestX=%TestY%\test3
    TestY=%TestZ%\test2
    TestZ=C:\Program Files\Java\jdk-11.0\test1
    :-(

    This - dear MicroSoft guys - is BUGGY! Such substitutions should/needs to work regardless of the ordering of the environment variables names! Unbelievable, that nobody at MS ever noticed and fixed this!
      My Computer


  2. Posts : 1,255
    Windows 10 Pro
       #2

    I wouldn't consider this a bug at all.

    In the example the variable M2 refers to the variable M2_HOME which is not defined until the next line. This is a forward reference. Forward references should not be assumed to work unless this is explicitly documented and I have never seen any documentation that states it is. Even if this was a bug, and I don't think it is, it could not be changed now. Doing so would likely have compatibility issues that override any potential benefits.
      My Computer


  3. mmo
    Posts : 140
    Windows 10
    Thread Starter
       #3

    Well - if the user could arrange and order those variables, yes - then one could consider this *not* a bug, because the user could order them such, that this case doesn't happen.
    But since the environment variables are ordered and saved alphabetically one cannot define substitutions of strings that happen to be alphabetically later than the one being defined. *I* consider this a bug!
    The assignment code should test whether the value to be assigned still contains any place-holders and - if so - first evaluate those. And it should do that recursively, until there are no more variables to be substituted (of course with some emergency exit in case one defined an endless cycle). *That* would IMHO be the correct implementation!
    Last edited by mmo; 07 Feb 2019 at 02:48.
      My Computer


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 12:55.
Find Us




Windows 10 Forums