Skip to content

Commit fa9fb1e

Browse files
committed
Refactor the JXPathFilter
1 parent 771b5fc commit fa9fb1e

1 file changed

Lines changed: 6 additions & 10 deletions

File tree

src/main/java/org/apache/commons/jxpath/ri/JXPathFilter.java

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,18 @@
2222

2323
/**
2424
* A filter to be used by JXPath, to evaluate the xpath string values to impose any restrictions.
25-
* This class implements specific filter interfaces, and implements methods in those.
25+
* This class implements specific filter interfaces, and implements methods in those.
2626
* For instance, it JXPathClassFilter interface, which is used to check if any restricted java classes are passed via xpath
2727
* JXPath uses this filter instance when an extension function instance is created.
2828
*/
2929
public class JXPathFilter implements JXPathClassFilter {
30-
private Set<String> allowedClassesList = null;
30+
private final Set<String> allowedClasses;
3131

3232
public JXPathFilter() {
33-
init();
34-
}
35-
36-
public void init() {
33+
this.allowedClasses = new HashSet<>();
3734
final String allowedClasses = System.getProperty("jxpath.class.allow");
3835
if (allowedClasses != null && !allowedClasses.isEmpty()) {
39-
allowedClassesList = new HashSet<>();
40-
allowedClassesList.addAll(Arrays.asList(allowedClasses.split(",")));
36+
this.allowedClasses.addAll(Arrays.asList(allowedClasses.split(",")));
4137
}
4238
}
4339

@@ -50,10 +46,10 @@ public void init() {
5046
*/
5147
@Override
5248
public boolean exposeToXPath(String className) {
53-
if (allowedClassesList == null || allowedClassesList.size() < 1) {
49+
if (allowedClasses.isEmpty()) {
5450
return false;
5551
}
5652

57-
return allowedClassesList.contains(className) || allowedClassesList.contains("*");
53+
return allowedClasses.contains(className) || allowedClasses.contains("*");
5854
}
5955
}

0 commit comments

Comments
 (0)