From fa9fb1ee4e5da6248dfade9a2f0b62c00ab0a795 Mon Sep 17 00:00:00 2001 From: Khaled Yakdan Date: Wed, 19 Oct 2022 22:05:57 +0200 Subject: [PATCH] Refactor the JXPathFilter --- .../apache/commons/jxpath/ri/JXPathFilter.java | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/main/java/org/apache/commons/jxpath/ri/JXPathFilter.java b/src/main/java/org/apache/commons/jxpath/ri/JXPathFilter.java index 92554ed9b..e5fe2ff78 100644 --- a/src/main/java/org/apache/commons/jxpath/ri/JXPathFilter.java +++ b/src/main/java/org/apache/commons/jxpath/ri/JXPathFilter.java @@ -22,22 +22,18 @@ /** * A filter to be used by JXPath, to evaluate the xpath string values to impose any restrictions. - * This class implements specific filter interfaces, and implements methods in those. + * This class implements specific filter interfaces, and implements methods in those. * For instance, it JXPathClassFilter interface, which is used to check if any restricted java classes are passed via xpath * JXPath uses this filter instance when an extension function instance is created. */ public class JXPathFilter implements JXPathClassFilter { - private Set allowedClassesList = null; + private final Set allowedClasses; public JXPathFilter() { - init(); - } - - public void init() { + this.allowedClasses = new HashSet<>(); final String allowedClasses = System.getProperty("jxpath.class.allow"); if (allowedClasses != null && !allowedClasses.isEmpty()) { - allowedClassesList = new HashSet<>(); - allowedClassesList.addAll(Arrays.asList(allowedClasses.split(","))); + this.allowedClasses.addAll(Arrays.asList(allowedClasses.split(","))); } } @@ -50,10 +46,10 @@ public void init() { */ @Override public boolean exposeToXPath(String className) { - if (allowedClassesList == null || allowedClassesList.size() < 1) { + if (allowedClasses.isEmpty()) { return false; } - return allowedClassesList.contains(className) || allowedClassesList.contains("*"); + return allowedClasses.contains(className) || allowedClasses.contains("*"); } }