zookeeper-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From eolive...@apache.org
Subject [zookeeper] branch master updated: ZOOKEEPER-3263: JAVA9/11 Warnings: Illegal reflective access in zookeer's kerberosUtil
Date Mon, 20 May 2019 15:18:46 GMT
This is an automated email from the ASF dual-hosted git repository.

eolivelli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/zookeeper.git


The following commit(s) were added to refs/heads/master by this push:
     new 777f0c1  ZOOKEEPER-3263: JAVA9/11 Warnings: Illegal reflective access in zookeer's
kerberosUtil
777f0c1 is described below

commit 777f0c15e73a8401a648c3cff93d20b3d3e4ee17
Author: Andor Molnar <andor@apache.org>
AuthorDate: Mon May 20 17:18:31 2019 +0200

    ZOOKEEPER-3263: JAVA9/11 Warnings: Illegal reflective access in zookeer's kerberosUtil
    
    Fixes warning messages of JDK 9/11 by upgrading libraries and refactoring `KerberosUtils`
based on experiences of [HADOOP-10848](https://issues.apache.org/jira/browse/HADOOP-10848)
    
    Reviewers please run unit tests with various JDK versions including 9 and 11, because
CI only runs on JDK 8. Thanks.
    
    Target branches are master and 3.5
    
    Author: Andor Molnar <andor@apache.org>
    
    Reviewers: Enrico Olivelli <eolivelli@apache.org>
    
    Closes #950 from anmolnar/ZOOKEEPER-3263
---
 build.xml                                          |  6 +++---
 ivy.xml                                            |  2 +-
 pom.xml                                            |  6 +++---
 zookeeper-docs/pom.xml                             |  2 +-
 zookeeper-server/pom.xml                           |  2 +-
 .../apache/zookeeper/server/util/KerberosUtil.java | 24 +++-------------------
 .../org/apache/zookeeper/ClientReconnectTest.java  |  2 +-
 .../zookeeper/server/ConnectionMetricsTest.java    |  7 +++++--
 .../server/FinalRequestProcessorTest.java          | 12 +++++------
 .../server/PrepRequestProcessorMetricsTest.java    | 10 +++++----
 .../zookeeper/server/quorum/LeaderBeanTest.java    |  4 ++--
 .../server/quorum/LearnerHandlerMetricsTest.java   |  6 +++---
 .../server/quorum/LearnerHandlerTest.java          | 12 +++++------
 .../zookeeper/server/quorum/LocalPeerBeanTest.java |  2 +-
 .../server/quorum/QuorumPeerMainTest.java          |  2 +-
 .../server/quorum/RemotePeerBeanTest.java          |  2 +-
 .../zookeeper/server/quorum/WatchLeakTest.java     |  2 +-
 .../zookeeper/server/util/SerializeUtilsTest.java  |  6 +++---
 18 files changed, 48 insertions(+), 61 deletions(-)

diff --git a/build.xml b/build.xml
index c0dc8fe..2f421e0 100644
--- a/build.xml
+++ b/build.xml
@@ -40,11 +40,11 @@ xmlns:cs="antlib:com.puppycrawl.tools.checkstyle.ant">
     <property name="netty.version" value="4.1.29.Final"/>
 
     <property name="junit.version" value="4.12"/>
-    <property name="mockito.version" value="1.8.5"/>
+    <property name="mockito.version" value="2.27.0"/>
     <property name="checkstyle.version" value="7.1.2"/>
     <property name="commons-collections.version" value="3.2.2"/>
 
-    <property name="bouncycastle.version" value="1.60"/>
+    <property name="bouncycastle.version" value="1.61"/>
 
     <property name="jdiff.version" value="1.0.9"/>
     <property name="xerces.version" value="1.4.4"/>
@@ -161,7 +161,7 @@ xmlns:cs="antlib:com.puppycrawl.tools.checkstyle.ant">
     <property name="contrib.dir" value="${basedir}/zookeeper-contrib"/>
     <property name="recipes.dir" value="${basedir}/zookeeper-recipes"/>
 
-    <property name="ivy.version" value="2.4.0"/>
+    <property name="ivy.version" value="2.5.0-rc1"/>
     <property name="ivy.url"
               value="https://repo1.maven.org/maven2/org/apache/ivy/ivy" />
     <property name="ivy.home" value="${user.home}/.ant" />
diff --git a/ivy.xml b/ivy.xml
index 6125980..c373bb5 100644
--- a/ivy.xml
+++ b/ivy.xml
@@ -68,7 +68,7 @@
       <exclude org="junit" module="junit"/>
     </dependency>
     <dependency org="junit" name="junit" rev="${junit.version}" conf="test->default"/>
-	<dependency org="org.mockito" name="mockito-all" rev="${mockito.version}"
+	<dependency org="org.mockito" name="mockito-core" rev="${mockito.version}"
                conf="test->default"/>
     <dependency org="com.puppycrawl.tools" name="checkstyle" rev="${checkstyle.version}"
                 conf="test->default">
diff --git a/pom.xml b/pom.xml
index 3e6cf7d..51ff7b4 100755
--- a/pom.xml
+++ b/pom.xml
@@ -274,7 +274,7 @@
     <audience-annotations.version>0.5.0</audience-annotations.version>
     <junit.version>4.12</junit.version>
     <log4j.version>1.2.17</log4j.version>
-    <mockito.version>1.8.5</mockito.version>
+    <mockito.version>2.27.0</mockito.version>
     <hamcrest.version>1.3</hamcrest.version>
     <commons-cli.version>1.2</commons-cli.version>
     <netty.version>4.1.29.Final</netty.version>
@@ -284,7 +284,7 @@
     <jline.version>2.11</jline.version>
     <snappy.version>1.1.7</snappy.version>
     <kerby.version>1.1.0</kerby.version>
-    <bouncycastle.version>1.60</bouncycastle.version>
+    <bouncycastle.version>1.61</bouncycastle.version>
     <commons-collections.version>3.2.2</commons-collections.version>
     <commons-lang.version>2.6</commons-lang.version>
     <dropwizard.version>3.2.5</dropwizard.version>
@@ -394,7 +394,7 @@
       </dependency>
       <dependency>
         <groupId>org.mockito</groupId>
-        <artifactId>mockito-all</artifactId>
+        <artifactId>mockito-core</artifactId>
         <version>${mockito.version}</version>
       </dependency>
       <dependency>
diff --git a/zookeeper-docs/pom.xml b/zookeeper-docs/pom.xml
index 47da323..d3c11c9 100644
--- a/zookeeper-docs/pom.xml
+++ b/zookeeper-docs/pom.xml
@@ -38,7 +38,7 @@
       <plugin>
         <groupId>com.ruleoftech</groupId>
         <artifactId>markdown-page-generator-plugin</artifactId>
-        <version>0.10</version>
+        <version>2.1.0</version>
         <executions>
           <execution>
             <phase>process-sources</phase>
diff --git a/zookeeper-server/pom.xml b/zookeeper-server/pom.xml
index f2a80ba..cc18882 100755
--- a/zookeeper-server/pom.xml
+++ b/zookeeper-server/pom.xml
@@ -141,7 +141,7 @@
     </dependency>
     <dependency>
       <groupId>org.mockito</groupId>
-      <artifactId>mockito-all</artifactId>
+      <artifactId>mockito-core</artifactId>
       <scope>test</scope>
     </dependency>
     <dependency>
diff --git a/zookeeper-server/src/main/java/org/apache/zookeeper/server/util/KerberosUtil.java
b/zookeeper-server/src/main/java/org/apache/zookeeper/server/util/KerberosUtil.java
index f5f4e26..af35ef7 100644
--- a/zookeeper-server/src/main/java/org/apache/zookeeper/server/util/KerberosUtil.java
+++ b/zookeeper-server/src/main/java/org/apache/zookeeper/server/util/KerberosUtil.java
@@ -18,28 +18,10 @@
 
 package org.apache.zookeeper.server.util;
 
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
+import javax.security.auth.kerberos.KerberosPrincipal;
 
 public class KerberosUtil {
-
-  public static String getDefaultRealm() 
-      throws ClassNotFoundException, NoSuchMethodException, 
-      IllegalArgumentException, IllegalAccessException, 
-      InvocationTargetException {
-    Object kerbConf;
-    Class<?> classRef;
-    Method getInstanceMethod;
-    Method getDefaultRealmMethod;
-    if (System.getProperty("java.vendor").contains("IBM")) {
-      classRef = Class.forName("com.ibm.security.krb5.internal.Config");
-    } else {
-      classRef = Class.forName("sun.security.krb5.Config");
-    }
-    getInstanceMethod = classRef.getMethod("getInstance", new Class<?>[0]);
-    kerbConf = getInstanceMethod.invoke(classRef, new Object[0]);
-    getDefaultRealmMethod = classRef.getDeclaredMethod("getDefaultRealm",
-         new Class<?>[0]);
-    return (String)getDefaultRealmMethod.invoke(kerbConf, new Object[0]);
+  public static String getDefaultRealm() throws IllegalArgumentException {
+    return new KerberosPrincipal("tmp", 1).getRealm();
   }
 }
diff --git a/zookeeper-server/src/test/java/org/apache/zookeeper/ClientReconnectTest.java
b/zookeeper-server/src/test/java/org/apache/zookeeper/ClientReconnectTest.java
index 566b915..4877534 100644
--- a/zookeeper-server/src/test/java/org/apache/zookeeper/ClientReconnectTest.java
+++ b/zookeeper-server/src/test/java/org/apache/zookeeper/ClientReconnectTest.java
@@ -18,7 +18,7 @@
 package org.apache.zookeeper;
 
 
-import static org.mockito.Matchers.anyLong;
+import static org.mockito.ArgumentMatchers.anyLong;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
diff --git a/zookeeper-server/src/test/java/org/apache/zookeeper/server/ConnectionMetricsTest.java
b/zookeeper-server/src/test/java/org/apache/zookeeper/server/ConnectionMetricsTest.java
index d6ade36..47d406f 100644
--- a/zookeeper-server/src/test/java/org/apache/zookeeper/server/ConnectionMetricsTest.java
+++ b/zookeeper-server/src/test/java/org/apache/zookeeper/server/ConnectionMetricsTest.java
@@ -35,12 +35,15 @@ import java.io.IOException;
 import java.net.InetSocketAddress;
 import java.net.Socket;
 import java.nio.ByteBuffer;
-import java.nio.channels.*;
+import java.nio.channels.SelectableChannel;
+import java.nio.channels.SelectionKey;
+import java.nio.channels.Selector;
+import java.nio.channels.SocketChannel;
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
 
 import static org.apache.zookeeper.server.NIOServerCnxnFactory.ZOOKEEPER_NIO_SESSIONLESS_CNXN_TIMEOUT;
-import static org.mockito.Matchers.any;
+import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
diff --git a/zookeeper-server/src/test/java/org/apache/zookeeper/server/FinalRequestProcessorTest.java
b/zookeeper-server/src/test/java/org/apache/zookeeper/server/FinalRequestProcessorTest.java
index c34d7c9..dc56f83 100644
--- a/zookeeper-server/src/test/java/org/apache/zookeeper/server/FinalRequestProcessorTest.java
+++ b/zookeeper-server/src/test/java/org/apache/zookeeper/server/FinalRequestProcessorTest.java
@@ -43,9 +43,9 @@ import java.util.List;
 import static org.hamcrest.Matchers.equalTo;
 import static org.junit.Assert.assertThat;
 import static org.junit.Assert.assertTrue;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.anyString;
-import static org.mockito.Matchers.eq;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.ArgumentMatchers.eq;
 import static org.mockito.Mockito.doAnswer;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
@@ -81,11 +81,11 @@ public class FinalRequestProcessorTest {
         doAnswer(new Answer() {
             @Override
             public Object answer(InvocationOnMock invocationOnMock) {
-                replyHeaders[0] = (ReplyHeader) invocationOnMock.getArguments()[0];
-                responseRecord[0] = (Record) invocationOnMock.getArguments()[1];
+                replyHeaders[0] = invocationOnMock.getArgument(0);
+                responseRecord[0] = invocationOnMock.getArgument(1);
                 return null;
             }
-        }).when(cnxn).sendResponse(any(ReplyHeader.class), any(Record.class), anyString());
+        }).when(cnxn).sendResponse(any(), any(), anyString());
 
         GetACLRequest getACLRequest = new GetACLRequest();
         getACLRequest.setPath(testPath);
diff --git a/zookeeper-server/src/test/java/org/apache/zookeeper/server/PrepRequestProcessorMetricsTest.java
b/zookeeper-server/src/test/java/org/apache/zookeeper/server/PrepRequestProcessorMetricsTest.java
index 90e2fe1..a277a1c 100644
--- a/zookeeper-server/src/test/java/org/apache/zookeeper/server/PrepRequestProcessorMetricsTest.java
+++ b/zookeeper-server/src/test/java/org/apache/zookeeper/server/PrepRequestProcessorMetricsTest.java
@@ -36,15 +36,17 @@ import org.slf4j.LoggerFactory;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.nio.ByteBuffer;
-import java.util.*;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.TimeUnit;
 
 import static org.hamcrest.number.OrderingComparison.greaterThan;
 import static org.hamcrest.number.OrderingComparison.greaterThanOrEqualTo;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.anyLong;
-import static org.mockito.Matchers.anyString;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyLong;
+import static org.mockito.ArgumentMatchers.anyString;
 import static org.mockito.Mockito.*;
 
 public class PrepRequestProcessorMetricsTest extends ZKTestCase {
diff --git a/zookeeper-server/src/test/java/org/apache/zookeeper/server/quorum/LeaderBeanTest.java
b/zookeeper-server/src/test/java/org/apache/zookeeper/server/quorum/LeaderBeanTest.java
index 38539b3..a6a5ec7 100644
--- a/zookeeper-server/src/test/java/org/apache/zookeeper/server/quorum/LeaderBeanTest.java
+++ b/zookeeper-server/src/test/java/org/apache/zookeeper/server/quorum/LeaderBeanTest.java
@@ -47,8 +47,8 @@ import java.util.Map;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.assertNotEquals;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.anyString;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyString;
 import static org.mockito.Mockito.doAnswer;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
diff --git a/zookeeper-server/src/test/java/org/apache/zookeeper/server/quorum/LearnerHandlerMetricsTest.java
b/zookeeper-server/src/test/java/org/apache/zookeeper/server/quorum/LearnerHandlerMetricsTest.java
index dc67147..a196ea5 100644
--- a/zookeeper-server/src/test/java/org/apache/zookeeper/server/quorum/LearnerHandlerMetricsTest.java
+++ b/zookeeper-server/src/test/java/org/apache/zookeeper/server/quorum/LearnerHandlerMetricsTest.java
@@ -24,7 +24,7 @@ import org.apache.zookeeper.server.ServerMetrics;
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
-import org.mockito.Matchers;
+import org.mockito.ArgumentMatchers;
 import org.mockito.invocation.InvocationOnMock;
 import org.mockito.stubbing.Answer;
 
@@ -35,7 +35,7 @@ import java.net.Socket;
 import java.util.Map;
 
 import static org.hamcrest.number.OrderingComparison.greaterThan;
-import static org.mockito.Matchers.any;
+import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.doAnswer;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
@@ -66,7 +66,7 @@ public class LearnerHandlerMetricsTest {
                 Thread.sleep(5);
                 return  null;
             }
-        }).when(oa).writeRecord(any(QuorumPacket.class), Matchers.anyString());
+        }).when(oa).writeRecord(any(QuorumPacket.class), ArgumentMatchers.anyString());
 
         learnerHandler = new MockLearnerHandler(socket, leader);
         learnerHandler.setOutputArchive(oa);
diff --git a/zookeeper-server/src/test/java/org/apache/zookeeper/server/quorum/LearnerHandlerTest.java
b/zookeeper-server/src/test/java/org/apache/zookeeper/server/quorum/LearnerHandlerTest.java
index c15a6bf..9848cd8 100644
--- a/zookeeper-server/src/test/java/org/apache/zookeeper/server/quorum/LearnerHandlerTest.java
+++ b/zookeeper-server/src/test/java/org/apache/zookeeper/server/quorum/LearnerHandlerTest.java
@@ -41,7 +41,7 @@ import org.apache.zookeeper.server.quorum.Leader.Proposal;
 import org.apache.zookeeper.server.util.ZxidUtils;
 import org.junit.Before;
 import org.junit.Test;
-import org.mockito.Matchers;
+import org.mockito.ArgumentMatchers;
 import org.mockito.invocation.InvocationOnMock;
 import org.mockito.stubbing.Answer;
 import org.slf4j.Logger;
@@ -137,11 +137,11 @@ public class LearnerHandlerTest extends ZKTestCase {
         // Intercept when startForwarding is called
         leader = mock(Leader.class);
         when(
-                leader.startForwarding(Matchers.any(LearnerHandler.class),
-                        Matchers.anyLong())).thenAnswer(new Answer() {
-            public Object answer(InvocationOnMock invocation) {
-                currentZxid = (Long) invocation.getArguments()[1];
-                return 0;
+                leader.startForwarding(ArgumentMatchers.any(LearnerHandler.class),
+                        ArgumentMatchers.anyLong())).thenAnswer(new Answer<Long>()
{
+            public Long answer(InvocationOnMock invocation) {
+                currentZxid = invocation.getArgument(1);
+                return 0L;
             }
         });
         when(leader.getZKDatabase()).thenReturn(db);
diff --git a/zookeeper-server/src/test/java/org/apache/zookeeper/server/quorum/LocalPeerBeanTest.java
b/zookeeper-server/src/test/java/org/apache/zookeeper/server/quorum/LocalPeerBeanTest.java
index 805b3cb..3554aac 100644
--- a/zookeeper-server/src/test/java/org/apache/zookeeper/server/quorum/LocalPeerBeanTest.java
+++ b/zookeeper-server/src/test/java/org/apache/zookeeper/server/quorum/LocalPeerBeanTest.java
@@ -22,7 +22,7 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
-import static org.mockito.Matchers.eq;
+import static org.mockito.ArgumentMatchers.eq;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
diff --git a/zookeeper-server/src/test/java/org/apache/zookeeper/server/quorum/QuorumPeerMainTest.java
b/zookeeper-server/src/test/java/org/apache/zookeeper/server/quorum/QuorumPeerMainTest.java
index d9534ca..146773b 100644
--- a/zookeeper-server/src/test/java/org/apache/zookeeper/server/quorum/QuorumPeerMainTest.java
+++ b/zookeeper-server/src/test/java/org/apache/zookeeper/server/quorum/QuorumPeerMainTest.java
@@ -20,7 +20,7 @@ package org.apache.zookeeper.server.quorum;
 
 import static org.apache.zookeeper.test.ClientBase.CONNECTION_TIMEOUT;
 import static org.apache.zookeeper.test.ClientBase.createEmptyTestDir;
-import static org.mockito.Matchers.any;
+import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.doCallRealMethod;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
diff --git a/zookeeper-server/src/test/java/org/apache/zookeeper/server/quorum/RemotePeerBeanTest.java
b/zookeeper-server/src/test/java/org/apache/zookeeper/server/quorum/RemotePeerBeanTest.java
index fbb0acc..08dff63 100644
--- a/zookeeper-server/src/test/java/org/apache/zookeeper/server/quorum/RemotePeerBeanTest.java
+++ b/zookeeper-server/src/test/java/org/apache/zookeeper/server/quorum/RemotePeerBeanTest.java
@@ -24,7 +24,7 @@ import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
-import static org.mockito.Matchers.eq;
+import static org.mockito.ArgumentMatchers.eq;
 
 import java.net.InetSocketAddress;
 
diff --git a/zookeeper-server/src/test/java/org/apache/zookeeper/server/quorum/WatchLeakTest.java
b/zookeeper-server/src/test/java/org/apache/zookeeper/server/quorum/WatchLeakTest.java
index d8667dc..4eebcf3 100644
--- a/zookeeper-server/src/test/java/org/apache/zookeeper/server/quorum/WatchLeakTest.java
+++ b/zookeeper-server/src/test/java/org/apache/zookeeper/server/quorum/WatchLeakTest.java
@@ -17,7 +17,7 @@
 
 package org.apache.zookeeper.server.quorum;
 
-import static org.mockito.Matchers.any;
+import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 import static org.junit.Assert.*;
diff --git a/zookeeper-server/src/test/java/org/apache/zookeeper/server/util/SerializeUtilsTest.java
b/zookeeper-server/src/test/java/org/apache/zookeeper/server/util/SerializeUtilsTest.java
index 61893f7..b2d5630 100644
--- a/zookeeper-server/src/test/java/org/apache/zookeeper/server/util/SerializeUtilsTest.java
+++ b/zookeeper-server/src/test/java/org/apache/zookeeper/server/util/SerializeUtilsTest.java
@@ -34,9 +34,9 @@ import java.io.IOException;
 import static org.junit.Assert.assertArrayEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.anyString;
-import static org.mockito.Matchers.eq;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.ArgumentMatchers.eq;
 import static org.mockito.Mockito.doAnswer;
 import static org.mockito.Mockito.inOrder;
 import static org.mockito.Mockito.mock;


Mime
View raw message