cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject [cxf] branch master updated: Fix a bunch of issues identified by error-prone
Date Tue, 05 Jun 2018 17:12:13 GMT
This is an automated email from the ASF dual-hosted git repository.

dkulp 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 a333d80  Fix a bunch of issues identified by error-prone
a333d80 is described below

commit a333d80fdb659cdf382400a63ae4d3fee21524d1
Author: Daniel Kulp <dkulp@apache.org>
AuthorDate: Tue Jun 5 13:10:42 2018 -0400

    Fix a bunch of issues identified by error-prone
---
 .../security/NameDigestPasswordCallbackHandler.java   |  5 ++++-
 .../security/NamePasswordCallbackHandler.java         |  5 ++++-
 pom.xml                                               | 15 +++++++++++++++
 .../apache/cxf/aegis/type/java5/AnnotationReader.java |  6 +++---
 .../org/apache/cxf/aegis/type/basic/ByteDataTest.java |  1 +
 .../java/org/apache/cxf/jaxrs/model/ProviderInfo.java |  2 +-
 .../org/apache/cxf/jaxrs/impl/UriBuilderImplTest.java |  3 ++-
 .../org/apache/cxf/jaxrs/utils/FormUtilsTest.java     |  1 +
 .../apache/cxf/jaxrs/utils/InjectionUtilsTest.java    |  1 +
 .../cxf/jaxrs/rx2/server/ReactiveIOInvoker.java       | 19 ++++++++++++++-----
 .../jaxrs/reactive/JAXRSRxJava2FlowableTest.java      | 17 ++++++++++++++---
 .../jaxrs/reactive/JAXRSRxJava2ObservableTest.java    |  6 +++++-
 .../systest/jaxrs/websocket/WebSocketTestClient.java  |  2 +-
 13 files changed, 66 insertions(+), 17 deletions(-)

diff --git a/core/src/main/java/org/apache/cxf/interceptor/security/NameDigestPasswordCallbackHandler.java
b/core/src/main/java/org/apache/cxf/interceptor/security/NameDigestPasswordCallbackHandler.java
index 3f8c374..75e6b1a 100644
--- a/core/src/main/java/org/apache/cxf/interceptor/security/NameDigestPasswordCallbackHandler.java
+++ b/core/src/main/java/org/apache/cxf/interceptor/security/NameDigestPasswordCallbackHandler.java
@@ -101,7 +101,10 @@ public class NameDigestPasswordCallbackHandler implements CallbackHandler
{
         for (Class<?> arg : PASSWORD_CALLBACK_TYPES) {
             try {
                 Method method = callback.getClass().getMethod(cbname, arg);
-                method.invoke(callback, arg == String.class ? password : password.toCharArray());
+                Object args[] = new Object[] {
+                    arg == String.class ? password : password.toCharArray()
+                };
+                method.invoke(callback, args);
                 return true;
             } catch (Exception e) {
                 // ignore and continue
diff --git a/core/src/main/java/org/apache/cxf/interceptor/security/NamePasswordCallbackHandler.java
b/core/src/main/java/org/apache/cxf/interceptor/security/NamePasswordCallbackHandler.java
index 81c34a3..908153d 100644
--- a/core/src/main/java/org/apache/cxf/interceptor/security/NamePasswordCallbackHandler.java
+++ b/core/src/main/java/org/apache/cxf/interceptor/security/NamePasswordCallbackHandler.java
@@ -93,7 +93,10 @@ public class NamePasswordCallbackHandler implements CallbackHandler {
         for (Class<?> arg : PASSWORD_CALLBACK_TYPES) {
             try {
                 Method method = callback.getClass().getMethod(cbname, arg);
-                method.invoke(callback, arg == String.class ? password : password.toCharArray());
+                Object args[] = new Object[] {
+                    arg == String.class ? password : password.toCharArray()
+                };
+                method.invoke(callback, args);
                 return true;
             } catch (Exception e) {
                 // ignore and continue
diff --git a/pom.xml b/pom.xml
index 94df195..6b3b77a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -495,7 +495,22 @@
                         <maxmem>256M</maxmem>
                         <fork>${cxf.compiler.fork}</fork>
                         <encoding>UTF-8</encoding>
+                        
+                        <!--compilerId>javac-with-errorprone</compilerId>
+                        <forceJavacCompilerUse>true</forceJavacCompilerUse-->
                     </configuration>
+                    <!--dependencies>
+                        <dependency>
+                            <groupId>org.codehaus.plexus</groupId>
+                            <artifactId>plexus-compiler-javac-errorprone</artifactId>
+                            <version>2.8.4</version>
+                        </dependency>
+                        <dependency>
+                            <groupId>com.google.errorprone</groupId>
+                            <artifactId>error_prone_core</artifactId>
+                            <version>2.3.1</version>
+                        </dependency>
+                    </dependencies-->
                 </plugin>
                 <plugin>
                     <groupId>org.apache.maven.plugins</groupId>
diff --git a/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/java5/AnnotationReader.java
b/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/java5/AnnotationReader.java
index 33f1b4f..bd1e248 100644
--- a/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/java5/AnnotationReader.java
+++ b/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/java5/AnnotationReader.java
@@ -278,7 +278,7 @@ public class AnnotationReader {
                 try {
                     Annotation ann = element.getAnnotation(annotation.asSubclass(Annotation.class));
                     if (ann != null) {
-                        Method method = ann.getClass().getMethod(name);
+                        Method method = ann.annotationType().getMethod(name);
                         Object value = method.invoke(ann);
                         if ((ignoredValue == null && value != null) || (ignoredValue
!= null
                                 && !ignoredValue.equals(value))) {
@@ -301,7 +301,7 @@ public class AnnotationReader {
                 try {
                     for (Annotation ann : anns) {
                         if (annotation.isInstance(ann)) {
-                            Method method = ann.getClass().getMethod(name);
+                            Method method = ann.annotationType().getMethod(name);
                             return method.invoke(ann);
                         }
                     }
@@ -331,7 +331,7 @@ public class AnnotationReader {
                 try {
                     Annotation ann = getAnnotation(method, index, annotation);
                     if (ann != null) {
-                        Object value = ann.getClass().getMethod(name).invoke(ann);
+                        Object value = ann.annotationType().getMethod(name).invoke(ann);
                         if ((ignoredValue == null && value != null) || (ignoredValue
!= null
                                 && !ignoredValue.equals(value))) {
                             return value;
diff --git a/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/basic/ByteDataTest.java
b/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/basic/ByteDataTest.java
index 7cfb0e6..ee80ae9 100644
--- a/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/basic/ByteDataTest.java
+++ b/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/basic/ByteDataTest.java
@@ -46,6 +46,7 @@ public class ByteDataTest extends AbstractAegisTest {
 
     }
 
+    @Test
     public void testBeanServiceWSDL() throws Exception {
         Document doc = getWSDLDocument("DataService");
         addNamespace("wsdl", WSDLConstants.NS_WSDL11);
diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ProviderInfo.java
b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ProviderInfo.java
index 73e7147..c1e3923 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ProviderInfo.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ProviderInfo.java
@@ -35,7 +35,7 @@ public class ProviderInfo<T> extends AbstractResourceInfo {
     }
 
     public ProviderInfo(T provider, Bus bus, boolean checkContexts, boolean custom) {
-        this(provider.getClass(), provider.getClass(), provider, bus, true, custom);
+        this(provider.getClass(), provider.getClass(), provider, bus, checkContexts, custom);
     }
 
     public ProviderInfo(Class<?> resourceClass, Class<?> serviceClass, T provider,
Bus bus, boolean custom) {
diff --git a/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/UriBuilderImplTest.java
b/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/UriBuilderImplTest.java
index 2ed7dec..c6c94f1 100644
--- a/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/UriBuilderImplTest.java
+++ b/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/UriBuilderImplTest.java
@@ -1236,10 +1236,11 @@ public class UriBuilderImplTest extends Assert {
         assertEquals(uri.toString(), expected);
     }
 
+    @Test
     public void testToTemplate() {
         String path1 = "ab";
         String[] path2 = {"a1", "{xy}", "3b "};
-        String expected = "ab/a1/{xy}/3b ";
+        String expected = "ab/a1/{xy}/3b%20";
 
         String template = UriBuilder.fromPath(path1).segment(path2).toTemplate();
         assertEquals(template, expected);
diff --git a/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/FormUtilsTest.java
b/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/FormUtilsTest.java
index 57b8d03..60d2aa2 100644
--- a/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/FormUtilsTest.java
+++ b/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/FormUtilsTest.java
@@ -63,6 +63,7 @@ public class FormUtilsTest extends Assert {
         assertEquals(HTTP_PARAM_VALUE2, params.get(HTTP_PARAM2).iterator().next());
     }
 
+    @Test
     public void populateMapFromStringFromHTTPWithProp() {
         mockObjects("false");
         EasyMock.replay(mockMessage, mockRequest);
diff --git a/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/InjectionUtilsTest.java
b/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/InjectionUtilsTest.java
index 2302288..d372b42 100644
--- a/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/InjectionUtilsTest.java
+++ b/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/InjectionUtilsTest.java
@@ -79,6 +79,7 @@ public class InjectionUtilsTest extends Assert {
         assertEquals(value, ((Id)id).getId());
     }
 
+    @Test
     public void testCollectionTypeFromArray() {
         assertNull(InjectionUtils.getCollectionType(String[].class));
     }
diff --git a/rt/rs/extensions/rx2/src/main/java/org/apache/cxf/jaxrs/rx2/server/ReactiveIOInvoker.java
b/rt/rs/extensions/rx2/src/main/java/org/apache/cxf/jaxrs/rx2/server/ReactiveIOInvoker.java
index e8871f4..35c0b08 100644
--- a/rt/rs/extensions/rx2/src/main/java/org/apache/cxf/jaxrs/rx2/server/ReactiveIOInvoker.java
+++ b/rt/rs/extensions/rx2/src/main/java/org/apache/cxf/jaxrs/rx2/server/ReactiveIOInvoker.java
@@ -25,6 +25,7 @@ import org.apache.cxf.message.Message;
 import io.reactivex.Flowable;
 import io.reactivex.Observable;
 import io.reactivex.Single;
+import io.reactivex.disposables.Disposable;
 
 public class ReactiveIOInvoker extends AbstractReactiveInvoker {
     protected AsyncResponseImpl checkFutureResponse(Message inMessage, Object result) {
@@ -34,28 +35,36 @@ public class ReactiveIOInvoker extends AbstractReactiveInvoker {
             return handleSingle(inMessage, (Single<?>)result);
         } else if (result instanceof Observable) {
             return handleObservable(inMessage, (Observable<?>)result);
-        } else {
-            return null;
         }
+        return null;
     }
     
     protected AsyncResponseImpl handleSingle(Message inMessage, Single<?> single) {
         final AsyncResponseImpl asyncResponse = new AsyncResponseImpl(inMessage);
-        single.subscribe(asyncResponse::resume, t -> handleThrowable(asyncResponse, t));
+        Disposable d = single.subscribe(asyncResponse::resume, t -> handleThrowable(asyncResponse,
t));
+        if (d == null) {
+            throw new IllegalStateException("Subscribe did not return a Disposable");
+        }
         return asyncResponse;
     }
 
     protected AsyncResponseImpl handleFlowable(Message inMessage, Flowable<?> f) {
         final AsyncResponseImpl asyncResponse = new AsyncResponseImpl(inMessage);
         if (!isStreamingSubscriberUsed(f, asyncResponse, inMessage)) {
-            f.subscribe(asyncResponse::resume, t -> handleThrowable(asyncResponse, t));
+            Disposable d = f.subscribe(asyncResponse::resume, t -> handleThrowable(asyncResponse,
t));
+            if (d == null) {
+                throw new IllegalStateException("Subscribe did not return a Disposable");
+            }
         }
         return asyncResponse;
     }
     
     protected AsyncResponseImpl handleObservable(Message inMessage, Observable<?> obs)
{
         final AsyncResponseImpl asyncResponse = new AsyncResponseImpl(inMessage);
-        obs.subscribe(v -> asyncResponse.resume(v), t -> handleThrowable(asyncResponse,
t));
+        Disposable d = obs.subscribe(v -> asyncResponse.resume(v), t -> handleThrowable(asyncResponse,
t));
+        if (d == null) {
+            throw new IllegalStateException("Subscribe did not return a Disposable");
+        }
         return asyncResponse;
     }
 
diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/reactive/JAXRSRxJava2FlowableTest.java
b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/reactive/JAXRSRxJava2FlowableTest.java
index ce051b1..af3cf2b 100644
--- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/reactive/JAXRSRxJava2FlowableTest.java
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/reactive/JAXRSRxJava2FlowableTest.java
@@ -39,6 +39,7 @@ import org.apache.cxf.jaxrs.rx2.client.FlowableRxInvokerProvider;
 import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
 
 import io.reactivex.Flowable;
+import io.reactivex.disposables.Disposable;
 
 import org.junit.BeforeClass;
 import org.junit.Test;
@@ -73,9 +74,12 @@ public class JAXRSRxJava2FlowableTest extends AbstractBusClientServerTestBase
{
             .get(HelloWorldBean.class);
         
         Holder<HelloWorldBean> holder = new Holder<HelloWorldBean>();
-        obs.subscribe(v -> {
+        Disposable d = obs.subscribe(v -> {
             holder.value = v;
         });
+        if (d == null) {
+            throw new IllegalStateException("Subscribe did not return a Disposable");
+        }
         Thread.sleep(3000);
         assertEquals("Hello", holder.value.getGreeting());
         assertEquals("World", holder.value.getAudience());
@@ -133,22 +137,29 @@ public class JAXRSRxJava2FlowableTest extends AbstractBusClientServerTestBase
{
         
         Thread.sleep(2000);
 
-        obs.map(
+        Disposable d = obs.map(
             s -> {
                 return s + s;
             })
             .subscribe(s -> assertDuplicateResponse(s));
+        if (d == null) {
+            throw new IllegalStateException("Subscribe did not return a Disposable");
+        }
     }
     @Test
     public void testGetHelloWorldAsyncObservable404() throws Exception {
         String address = "http://localhost:" + PORT + "/rx2/flowable/textAsync404";
         Invocation.Builder b = ClientBuilder.newClient().register(new FlowableRxInvokerProvider())
             .target(address).request();
-        b.rx(FlowableRxInvoker.class).get(String.class).subscribe(
+        Disposable d = b.rx(FlowableRxInvoker.class).get(String.class).subscribe(
             s -> {
                 fail("Exception expected");
             },
             t -> validateT((ExecutionException)t));
+        if (d == null) {
+            throw new IllegalStateException("Subscribe did not return a Disposable");
+        }
+        
     }
 
     private void validateT(ExecutionException t) {
diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/reactive/JAXRSRxJava2ObservableTest.java
b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/reactive/JAXRSRxJava2ObservableTest.java
index 724a0ff..dc8ef13 100644
--- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/reactive/JAXRSRxJava2ObservableTest.java
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/reactive/JAXRSRxJava2ObservableTest.java
@@ -33,6 +33,7 @@ import org.apache.cxf.jaxrs.rx2.client.ObservableRxInvokerProvider;
 import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
 
 import io.reactivex.Observable;
+import io.reactivex.disposables.Disposable;
 
 import org.junit.BeforeClass;
 import org.junit.Test;
@@ -59,9 +60,12 @@ public class JAXRSRxJava2ObservableTest extends AbstractBusClientServerTestBase
             .get(HelloWorldBean.class);
         
         Holder<HelloWorldBean> holder = new Holder<HelloWorldBean>();
-        obs.subscribe(v -> {
+        Disposable d = obs.subscribe(v -> {
             holder.value = v;
         });
+        if (d == null) {
+            throw new IllegalStateException("Subscribe did not return a Disposable");
+        }
         Thread.sleep(2000);
         assertEquals("Hello", holder.value.getGreeting());
         assertEquals("World", holder.value.getAudience());
diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/websocket/WebSocketTestClient.java
b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/websocket/WebSocketTestClient.java
index 6ab9bcf..aea4037 100644
--- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/websocket/WebSocketTestClient.java
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/websocket/WebSocketTestClient.java
@@ -134,7 +134,7 @@ class WebSocketTestClient {
         }
 
         public void onFragment(byte[] fragment, boolean last) {
-            LOG.info("[ws] received fragment bytes (last?" + last + ") --> " + fragment);
+            LOG.info("[ws] received fragment bytes (last?" + last + ") --> " + new String(fragment));
             processFragments(fragment, last);
         }
 

-- 
To stop receiving notification emails like this one, please contact
dkulp@apache.org.

Mime
View raw message