add an extra unit test
diff --git a/core/src/main/java/com/opensymphony/xwork2/ognl/OgnlUtil.java b/core/src/main/java/com/opensymphony/xwork2/ognl/OgnlUtil.java
index 024371b..13691d5 100644
--- a/core/src/main/java/com/opensymphony/xwork2/ognl/OgnlUtil.java
+++ b/core/src/main/java/com/opensymphony/xwork2/ognl/OgnlUtil.java
@@ -102,7 +102,8 @@
@Inject(value = XWorkConstants.OGNL_EXCLUDED_CLASSES, required = false)
public void setExcludedClasses(String commaDelimitedClasses) {
- Set<Class<?>> excludedClasses = this.excludedClasses;
+ Set<Class<?>> excludedClasses = new HashSet<>();
+ excludedClasses.addAll(this.excludedClasses);
excludedClasses.addAll(parseExcludedClasses(commaDelimitedClasses));
this.excludedClasses = Collections.unmodifiableSet(excludedClasses);
}
@@ -124,7 +125,8 @@
@Inject(value = XWorkConstants.OGNL_EXCLUDED_PACKAGE_NAME_PATTERNS, required = false)
public void setExcludedPackageNamePatterns(String commaDelimitedPackagePatterns) {
- Set<Pattern> excludedPackageNamePatterns = this.excludedPackageNamePatterns;
+ Set<Pattern> excludedPackageNamePatterns = new HashSet<>();
+ excludedPackageNamePatterns.addAll(this.excludedPackageNamePatterns);
excludedPackageNamePatterns.addAll(parseExcludedPackageNamePatterns(commaDelimitedPackagePatterns));
this.excludedPackageNamePatterns = Collections.unmodifiableSet(excludedPackageNamePatterns);
}
@@ -142,7 +144,8 @@
@Inject(value = XWorkConstants.OGNL_EXCLUDED_PACKAGE_NAMES, required = false)
public void setExcludedPackageNames(String commaDelimitedPackageNames) {
- Set<String> excludedPackageNames = this.excludedPackageNames;
+ Set<String> excludedPackageNames = new HashSet<>();
+ excludedPackageNames.addAll(this.excludedPackageNames);
excludedPackageNames.addAll(parseExcludedPackageNames(commaDelimitedPackageNames));
this.excludedPackageNames = Collections.unmodifiableSet(excludedPackageNames);
}
diff --git a/core/src/test/java/com/opensymphony/xwork2/ognl/OgnlUtilStrutsTest.java b/core/src/test/java/com/opensymphony/xwork2/ognl/OgnlUtilStrutsTest.java
new file mode 100644
index 0000000..bd371dd
--- /dev/null
+++ b/core/src/test/java/com/opensymphony/xwork2/ognl/OgnlUtilStrutsTest.java
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package com.opensymphony.xwork2.ognl;
+
+import org.apache.struts2.StrutsInternalTestCase;
+
+public class OgnlUtilStrutsTest extends StrutsInternalTestCase {
+
+ private OgnlUtil ognlUtil;
+
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+ ognlUtil = container.getInstance(OgnlUtil.class);
+ }
+
+ public void testDefaultExcludes() {
+ ognlUtil.setExcludedClasses("");
+ ognlUtil.setExcludedPackageNames("");
+ ognlUtil.setExcludedPackageNamePatterns("");
+ assertTrue(ognlUtil.getExcludedClasses().size() > 0);
+ assertTrue(ognlUtil.getExcludedPackageNames().size() > 0);
+
+ try {
+ ognlUtil.getExcludedClasses().clear();
+ } catch (Exception ex){
+ assertTrue(ex instanceof UnsupportedOperationException);
+ }
+ try {
+ ognlUtil.getExcludedPackageNames().clear();
+ } catch (Exception ex){
+ assertTrue(ex instanceof UnsupportedOperationException);
+ }
+ try {
+ ognlUtil.getExcludedPackageNamePatterns().clear();
+ } catch (Exception ex){
+ assertTrue(ex instanceof UnsupportedOperationException);
+ }
+ }
+}