wso2 / balana

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Bug in ConfigurationStore.getArgs - order of arguments missed

MRamonLeon opened this issue · comments

I do a PolicyFinderModule with a constructor with 9 arguments. When balana build de configuration it fails because the arguments of my constructor are in bad order. I put it all in correct order in the balana.xml file, but when it parse the configuration, it fails.

I think it's because in the method org.wso2.balana.ConfigurationStore.getArgs the arguments are stored in a Set, instead of a List. In that point, the order is missed.

This is the code:

private Set getArgs(Node root) {
        Set args = new HashSet();
        NodeList children = root.getChildNodes();

        for (int i = 0; i < children.getLength(); i++) {
            Node child = children.item(i);
            String name = DOMHelper.getLocalName(child);

            if (child.getNodeType() == Node.ELEMENT_NODE) {
                if (name.equals("string")) {
                    args.add(child.getFirstChild().getNodeValue());
                } else if (name.equals("set")) {
                    args.add(getArgs(child));
                } else {
                    throw new IllegalArgumentException("unkown arg type: " + name);
                }
            }
        }

        return args;
    }

The problem is that args is a Set, but It must be a List in order to keep the order in the xml.

Can you fix it?

Thanks.

I've created a pull request for this issue where I changed the HashSet to a LinkedHashSet. LinkedHashSets keep the order of the arguments. Lists cannot be used since most constructors need Set and not List.