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:16:28 GMT
Repository: cxf
Updated Branches:
  refs/heads/master d391d9371 -> d45de9c25


[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/d45de9c2
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/d45de9c2
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/d45de9c2

Branch: refs/heads/master
Commit: d45de9c2548f38798954016faa6ac207257ad12c
Parents: d391d93
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:15:50 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/d45de9c2/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 2cc8341..7a8bad5 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(Message m) {
         Collection<Assertion> alternative = null;
         if (requestor) {
-            alternative = engine.getAlternativeSelector().selectAlternative(policy, engine,
assertor, null, m);
+            if (engine.isEnabled()) {
+                alternative = engine.getAlternativeSelector().selectAlternative(policy, engine,
assertor, null, m);
+            } else {
+                // use an empty list to avoid getting NPE
+                alternative = Collections.emptyList();
+            }
         } else {
             alternative = getSupportedAlternatives(m);
         }

http://git-wip-us.apache.org/repos/asf/cxf/blob/d45de9c2/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 e3bb7b3..42dc83b 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
@@ -166,6 +166,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, m)).andReturn(null);
 
@@ -179,6 +180,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, m)).andReturn(alternative);
@@ -187,6 +189,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(m);
+        } 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();
     }
 
     private MessageImpl createMessage() {


Mime
View raw message