wso2 / balana

Apache License 2.0
122 stars 108 forks source link

Null reference exception when using general bag functions with custom data types. #144

Closed mdrozdo closed 3 years ago

mdrozdo commented 4 years ago

Description: If Balana is configured with a custom data type and a bag function operating on it (i.e. registered using the public GeneralBagFunction(String functionName, String datatype, String functionType) constructor), the code throws NullReferenceException from the GeneralBagFunction.returnsBag() function.

Affected Product Version: 1.2.5

Steps to reproduce: Register a custom datatype e.g.:

AttributeFactory sattr = StandardAttributeFactory.getNewFactory();
sattr.addDatatype(GeometryAttribute.identifier, new GeometryAttributeProxy());
Balana.getInstance().setAttributeFactory(sattr);

and register an associated bag function:

String functionName;
functionName = bagPrefix + BagFunction.NAME_BASE_ONE_AND_ONLY;
factory.addFunction(BagFunction.getOneAndOnlyInstance(functionName, GeometryAttribute.identifier));

Then try to evaluate the policy using such function.

The problem is due to the fact that when using the aforementioned constructor, the paramMap collection is not initialized with the function name, but rather the function type (e.g. "-one-and-only"). Therefore the GeneralBagFunction.returnsBag() should also use function type and not function name.

mdrozdo commented 4 years ago

The issue was introduced in https://github.com/wso2/balana/commit/647338610fc689d799af0f3d4e8222947ef42155 due to overriding in GeneralBagFunction:

    @Override
    public final boolean returnsBag() {

        return getReturnsBag(getFunctionName());
    }

I tried removing this override and the tests pass (it should just use the returnsBag field underneath). Is there any reason for this override?

senthalan commented 3 years ago

Closing as the PR is merged. Thank you for your valuable contribution.