cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a.@apache.org
Subject git commit: [CXF-5878] Disabling policy engine causes NPE
Date Wed, 30 Jul 2014 09:31:38 GMT
Repository: cxf
Updated Branches:
  refs/heads/2.7.x-fixes 59e5665d8 -> 778ab445b


[CXF-5878] Disabling policy engine causes NPE


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/778ab445
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/778ab445
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/778ab445

Branch: refs/heads/2.7.x-fixes
Commit: 778ab445bd2db01ecea966f1f50236d2bcb6b950
Parents: 59e5665
Author: Akitoshi Yoshida <ay@apache.org>
Authored: Wed Jul 30 11:07:19 2014 +0200
Committer: Akitoshi Yoshida <ay@apache.org>
Committed: Wed Jul 30 11:30:41 2014 +0200

----------------------------------------------------------------------
 .../apache/cxf/ws/policy/EndpointPolicyImpl.java    |  8 +++++++-
 .../cxf/ws/policy/EndpointPolicyImplTest.java       | 16 ++++++++++++++++
 2 files changed, 23 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/778ab445/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/EndpointPolicyImpl.java
----------------------------------------------------------------------
diff --git a/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/EndpointPolicyImpl.java b/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/EndpointPolicyImpl.java
index 3ff6c62..c97fb98 100644
--- a/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/EndpointPolicyImpl.java
+++ b/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/EndpointPolicyImpl.java
@@ -21,6 +21,7 @@ package org.apache.cxf.ws.policy;
 
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.Iterator;
 import java.util.LinkedHashSet;
 import java.util.List;
@@ -158,7 +159,12 @@ public class EndpointPolicyImpl implements EndpointPolicy {
     void chooseAlternative() {
         Collection<Assertion> alternative = null;
         if (requestor) {
-            alternative = engine.getAlternativeSelector().selectAlternative(policy, engine,
assertor, null);
+            if (engine.isEnabled()) {
+                alternative = engine.getAlternativeSelector().selectAlternative(policy, engine,
assertor, null);
+            } else {
+                // use an empty list to avoid getting NPE
+                alternative = Collections.emptyList();
+            }
         } else {
             alternative = getSupportedAlternatives();
         }

http://git-wip-us.apache.org/repos/asf/cxf/blob/778ab445/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/EndpointPolicyImplTest.java
----------------------------------------------------------------------
diff --git a/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/EndpointPolicyImplTest.java
b/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/EndpointPolicyImplTest.java
index eac5bda..be2617f 100644
--- a/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/EndpointPolicyImplTest.java
+++ b/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/EndpointPolicyImplTest.java
@@ -159,6 +159,7 @@ public class EndpointPolicyImplTest extends Assert {
         EndpointPolicyImpl epi = new EndpointPolicyImpl(null, engine, true, assertor);
         epi.setPolicy(policy);
 
+        EasyMock.expect(engine.isEnabled()).andReturn(true).anyTimes();
         EasyMock.expect(engine.getAlternativeSelector()).andReturn(selector);
         EasyMock.expect(selector.selectAlternative(policy, engine, assertor, null)).andReturn(null);
 
@@ -172,6 +173,7 @@ public class EndpointPolicyImplTest extends Assert {
         control.verify();
 
         control.reset();
+        EasyMock.expect(engine.isEnabled()).andReturn(true).anyTimes();
         EasyMock.expect(engine.getAlternativeSelector()).andReturn(selector);
         Collection<Assertion> alternative = new ArrayList<Assertion>();
         EasyMock.expect(selector.selectAlternative(policy, engine, assertor, null)).andReturn(alternative);
@@ -180,6 +182,20 @@ public class EndpointPolicyImplTest extends Assert {
         Collection<Assertion> choice = epi.getChosenAlternative();
         assertSame(choice, alternative);
         control.verify();
+
+        control.reset();
+        EasyMock.expect(engine.isEnabled()).andReturn(false).anyTimes();
+        EasyMock.expect(engine.getAlternativeSelector()).andReturn(null).anyTimes();
+        control.replay();
+        try {
+            epi.chooseAlternative();
+        } catch (Exception ex) {
+            // no NPE expected
+            fail("No Exception expected: " + ex);
+        }
+        choice = epi.getChosenAlternative();
+        assertTrue("not an empty list", choice != null && choice.isEmpty());
+        control.verify();
     }
 
     @Test


Mime
View raw message