azure-devops-java-sdk icon indicating copy to clipboard operation
azure-devops-java-sdk copied to clipboard

VariableGroupMap always assign the same value to variables

Open francispage opened this issue 1 year ago • 2 comments

Good job for this library! I like it.

In VariableGroupMap you always set the same value to all variables so I had to override the method in a child class.

public class VariableGroupMap extends BaseAbstractMethod {
    private final Map<String, ConfigurationVariableValue> map = new HashMap<>();
    **private final ConfigurationVariableValue variableValue = new ConfigurationVariableValue();**

    public VariableGroupMap() {
    }

    public void put(String name, String value) {
        **variableValue.setValue(value);**
        map.put(name, variableValue); --> same reference used for all variables in the library
    }

You always use the same object so all variables have the same reference. ConfigurationVariableValue should be created each time so have different value per key.

I made it work with this hack:

public static class VariableGroupMapInternal extends VariableGroupMap {

        @Override
        public void put(String name, String value) {
            ConfigurationVariableValue variableValue = new ConfigurationVariableValue();
            variableValue.setValue(value);
            this.get().put(name, variableValue);
        }

    }

francispage avatar May 01 '24 19:05 francispage

Hiya @francispage, Thanks for pointing it out. If you can create a PR, I will merge the changes.

hkarthik7 avatar May 07 '24 01:05 hkarthik7

Hi @francispage, I've applied the fixed and released a new version 5.0.12.

hkarthik7 avatar Jun 28 '24 13:06 hkarthik7