You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by bu...@apache.org on 2021/03/09 20:04:51 UTC
[cxf] branch master updated: cxf-rt-ws-policy: fix PMD rule:
UnusedAssignment
This is an automated email from the ASF dual-hosted git repository.
buhhunyx pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cxf.git
The following commit(s) were added to refs/heads/master by this push:
new 4f0cf06 cxf-rt-ws-policy: fix PMD rule: UnusedAssignment
4f0cf06 is described below
commit 4f0cf0632192b9327562ff65ca95546c73311b50
Author: Alexey Markevich <bu...@gmail.com>
AuthorDate: Tue Mar 9 23:03:28 2021 +0300
cxf-rt-ws-policy: fix PMD rule: UnusedAssignment
---
.../main/java/org/apache/cxf/ws/policy/EndpointPolicyImpl.java | 6 +++---
.../src/main/java/org/apache/cxf/ws/policy/PolicyUtils.java | 8 ++------
.../src/main/java/org/apache/cxf/ws/policy/WSPolicyFeature.java | 2 +-
.../external/EndpointReferenceDomainExpressionBuilder.java | 2 +-
.../policy/attachment/external/ExternalAttachmentProvider.java | 7 +++----
.../policy/attachment/wsdl11/Wsdl11AttachmentPolicyProvider.java | 2 +-
.../cxf/ws/policy/IgnorablePolicyInterceptorProviderTest.java | 9 ++++++---
.../attachment/wsdl11/Wsdl11AttachmentPolicyProviderTest.java | 4 ++--
8 files changed, 19 insertions(+), 21 deletions(-)
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 b8d9a96..98f9586 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
@@ -157,7 +157,7 @@ public class EndpointPolicyImpl implements EndpointPolicy {
}
void chooseAlternative(Message m) {
- Collection<Assertion> alternative = null;
+ final Collection<Assertion> alternative;
if (requestor) {
if (engine.isEnabled()) {
alternative = engine.getAlternativeSelector().selectAlternative(policy, engine, assertor, null, m);
@@ -221,7 +221,7 @@ public class EndpointPolicyImpl implements EndpointPolicy {
// add assertions for specific inbound (in case of a server endpoint) or outbound
// (in case of a client endpoint) messages
for (BindingOperationInfo boi : ei.getBinding().getOperations()) {
- EffectivePolicy p = null;
+ EffectivePolicy p;
if (!this.requestor) {
p = engine.getEffectiveServerRequestPolicy(ei, boi, m);
Collection<Assertion> c = engine.getAssertions(p, false);
@@ -302,7 +302,7 @@ public class EndpointPolicyImpl implements EndpointPolicy {
}
}
- List<Interceptor<? extends Message>> tmp = null;
+ final List<Interceptor<? extends Message>> tmp;
if (requestor) {
tmp = new ArrayList<>(out);
out.clear();
diff --git a/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/PolicyUtils.java b/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/PolicyUtils.java
index 9eaa9d0..0513558 100644
--- a/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/PolicyUtils.java
+++ b/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/PolicyUtils.java
@@ -178,19 +178,15 @@ public final class PolicyUtils {
nl(buf);
if (pc instanceof PolicyContainingAssertion) {
PolicyComponent nested = ((PolicyContainingAssertion)pc).getPolicy();
- level++;
- printPolicyComponent(nested, buf, level);
- level--;
+ printPolicyComponent(nested, buf, level + 1);
}
} else {
- level++;
List<PolicyComponent> children = CastUtils.cast(((PolicyOperator)pc).getPolicyComponents(),
PolicyComponent.class);
nl(buf);
for (PolicyComponent child : children) {
- printPolicyComponent(child, buf, level);
+ printPolicyComponent(child, buf, level + 1);
}
- level--;
}
}
diff --git a/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/WSPolicyFeature.java b/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/WSPolicyFeature.java
index ba01119..d619295 100644
--- a/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/WSPolicyFeature.java
+++ b/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/WSPolicyFeature.java
@@ -272,7 +272,7 @@ public class WSPolicyFeature extends AbstractFeature {
}
Policy resolveReference(PolicyReference ref, PolicyBuilder builder, Bus bus, DescriptionInfo i) {
- Policy p = null;
+ final Policy p;
if (!ref.getURI().startsWith("#")) {
String base = i == null ? null : i.getBaseURI();
p = resolveExternal(ref, base, bus);
diff --git a/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/attachment/external/EndpointReferenceDomainExpressionBuilder.java b/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/attachment/external/EndpointReferenceDomainExpressionBuilder.java
index b6f0b65..74b768a 100644
--- a/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/attachment/external/EndpointReferenceDomainExpressionBuilder.java
+++ b/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/attachment/external/EndpointReferenceDomainExpressionBuilder.java
@@ -59,7 +59,7 @@ public class EndpointReferenceDomainExpressionBuilder implements DomainExpressio
}
public DomainExpression build(Element e) {
- Object obj = null;
+ Object obj;
try {
obj = JAXBUtils.unmarshall(createJAXBContext(), e);
} catch (JAXBException ex) {
diff --git a/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/attachment/external/ExternalAttachmentProvider.java b/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/attachment/external/ExternalAttachmentProvider.java
index ba40a64..6bb9ac6 100644
--- a/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/attachment/external/ExternalAttachmentProvider.java
+++ b/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/attachment/external/ExternalAttachmentProvider.java
@@ -160,9 +160,8 @@ public class ExternalAttachmentProvider extends AbstractPolicyProvider {
// read the document and build the attachments
attachments = new ArrayList<>();
- Document doc = null;
- try {
- InputStream is = location.getInputStream();
+ final Document doc;
+ try (InputStream is = location.getInputStream()) {
if (null == is) {
throw new PolicyException(
new org.apache.cxf.common.i18n.Message(
@@ -224,7 +223,7 @@ public class ExternalAttachmentProvider extends AbstractPolicyProvider {
}
Policy resolveReference(PolicyReference ref, Document doc) {
- Policy p = null;
+ final Policy p;
if (isExternal(ref)) {
p = resolveExternal(ref, doc.getBaseURI());
} else {
diff --git a/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/attachment/wsdl11/Wsdl11AttachmentPolicyProvider.java b/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/attachment/wsdl11/Wsdl11AttachmentPolicyProvider.java
index 30727f6..6d09420 100644
--- a/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/attachment/wsdl11/Wsdl11AttachmentPolicyProvider.java
+++ b/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/attachment/wsdl11/Wsdl11AttachmentPolicyProvider.java
@@ -261,7 +261,7 @@ public class Wsdl11AttachmentPolicyProvider extends AbstractPolicyProvider {
}
Policy resolveReference(PolicyReference ref, DescriptionInfo di) {
- Policy p = null;
+ final Policy p;
if (isExternal(ref)) {
String uri = di.getBaseURI();
if (uri == null) {
diff --git a/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/IgnorablePolicyInterceptorProviderTest.java b/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/IgnorablePolicyInterceptorProviderTest.java
index 20d9201..db2b18b 100755
--- a/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/IgnorablePolicyInterceptorProviderTest.java
+++ b/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/IgnorablePolicyInterceptorProviderTest.java
@@ -140,11 +140,11 @@ public class IgnorablePolicyInterceptorProviderTest {
@Test
public void testTwoBuses() {
- ClassPathXmlApplicationContext context = null;
Bus cxf1 = null;
Bus cxf2 = null;
try {
- context = new ClassPathXmlApplicationContext("/org/apache/cxf/ws/policy/ignorable-policy2.xml");
+ ClassPathXmlApplicationContext context =
+ new ClassPathXmlApplicationContext("/org/apache/cxf/ws/policy/ignorable-policy2.xml");
cxf1 = (Bus)context.getBean("cxf1");
assertNotNull(cxf1);
@@ -175,8 +175,11 @@ public class IgnorablePolicyInterceptorProviderTest {
} finally {
if (null != cxf1) {
cxf1.shutdown(true);
- BusFactory.setDefaultBus(null);
}
+ if (null != cxf2) {
+ cxf2.shutdown(true);
+ }
+ BusFactory.setDefaultBus(null);
}
}
diff --git a/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/attachment/wsdl11/Wsdl11AttachmentPolicyProviderTest.java b/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/attachment/wsdl11/Wsdl11AttachmentPolicyProviderTest.java
index faa36f5..9b71f10 100644
--- a/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/attachment/wsdl11/Wsdl11AttachmentPolicyProviderTest.java
+++ b/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/attachment/wsdl11/Wsdl11AttachmentPolicyProviderTest.java
@@ -173,7 +173,7 @@ public class Wsdl11AttachmentPolicyProviderTest {
// one extension of type Policy, without assertion builder
try {
- p = app.getElementPolicy(services[2]);
+ app.getElementPolicy(services[2]);
fail("Expected PolicyException not thrown.");
} catch (PolicyException ex) {
// expected
@@ -213,7 +213,7 @@ public class Wsdl11AttachmentPolicyProviderTest {
// one extension of type Policy, without assertion builder
try {
- ep = app.getEffectivePolicy(services[2], null);
+ app.getEffectivePolicy(services[2], null);
fail("Expected PolicyException not thrown.");
} catch (PolicyException ex) {
// expected