Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WW-5340 Preliminary refactor of OgnlUtil #746

Merged
merged 4 commits into from
Sep 26, 2023

Conversation

kusalk
Copy link
Member

@kusalk kusalk commented Aug 31, 2023

WW-5340

I've refactored this class to improve both readability and maintainability.

My primary goal was to consolidate calls to ognl.Ognl, specifically the following functions:

  • #getValue: 5 calls to 1
  • #setValue: 2 calls to 1
  • #parseExpression: 4 calls to 1

Functionally, there are only 2 changes:

  • Removed redundant tree validation from OgnlUtil#setValue
  • Cache expressions prior to tree validation (i.e. even if validation fails)

@kusalk kusalk force-pushed the WW-5340-ognlutil-refactor branch from 14d3435 to 65ff242 Compare August 31, 2023 07:29
@kusalk kusalk marked this pull request as ready for review August 31, 2023 07:39
@@ -592,58 +582,55 @@
}

public Object getValue(final String name, final Map<String, Object> context, final Object root) throws OgnlException {
return compileAndExecute(name, context, tree -> Ognl.getValue(tree, context, root));
return getValue(name, context, root, null);

Check failure

Code scanning / CodeQL

OGNL Expression Language statement with user-controlled input

OGNL Expression Language statement depends on a [user-provided value](1). OGNL Expression Language statement depends on a [user-provided value](2). OGNL Expression Language statement depends on a [user-provided value](3). OGNL Expression Language statement depends on a [user-provided value](4). OGNL Expression Language statement depends on a [user-provided value](5). OGNL Expression Language statement depends on a [user-provided value](6). OGNL Expression Language statement depends on a [user-provided value](7). OGNL Expression Language statement depends on a [user-provided value](8). OGNL Expression Language statement depends on a [user-provided value](9). OGNL Expression Language statement depends on a [user-provided value](10). OGNL Expression Language statement depends on a [user-provided value](11). OGNL Expression Language statement depends on a [user-provided value](12).
}
Ognl.setValue(tree, context, root, value);

Check failure

Code scanning / CodeQL

OGNL Expression Language statement with user-controlled input

OGNL Expression Language statement depends on a [user-provided value](1). OGNL Expression Language statement depends on a [user-provided value](2). OGNL Expression Language statement depends on a [user-provided value](3).
for (TreeValidator validator : treeValidators) {
validator.validate(tree, checkContext);
}
return (T) Ognl.getValue(tree, context, root, resultType);

Check failure

Code scanning / CodeQL

OGNL Expression Language statement with user-controlled input

OGNL Expression Language statement depends on a [user-provided value](1). OGNL Expression Language statement depends on a [user-provided value](2). OGNL Expression Language statement depends on a [user-provided value](3). OGNL Expression Language statement depends on a [user-provided value](4). OGNL Expression Language statement depends on a [user-provided value](5). OGNL Expression Language statement depends on a [user-provided value](6). OGNL Expression Language statement depends on a [user-provided value](7). OGNL Expression Language statement depends on a [user-provided value](8). OGNL Expression Language statement depends on a [user-provided value](9). OGNL Expression Language statement depends on a [user-provided value](10). OGNL Expression Language statement depends on a [user-provided value](11). OGNL Expression Language statement depends on a [user-provided value](12).
@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

95.1% 95.1% Coverage
0.0% 0.0% Duplication

@kusalk kusalk requested a review from lukaszlenart September 6, 2023 01:51
Copy link
Member

@lukaszlenart lukaszlenart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@lukaszlenart lukaszlenart merged commit 19d26b2 into master Sep 26, 2023
@lukaszlenart lukaszlenart deleted the WW-5340-ognlutil-refactor branch September 26, 2023 09:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants