Skip to content

Commit

Permalink
ZOOKEEPER-2914: compiler warning using java 9
Browse files Browse the repository at this point in the history
Replaced deprecated methods (Class.newInstance()) and removed redundant cast

Author: Andor Molnar <[email protected]>

Reviewers: Patrick Hunt <[email protected]>

Closes apache#392 from dolphy17/ZOOKEEPER-2914 and squashes the following commits:

ab7bd5e [Andor Molnar] Reverted explicit case, because java 1.7 requires it to compile
b2d400b [Andor Molnar] Replaced Class.newInstance() methods (deprecated in Java 9) with Constructor.newInstance()

Change-Id: Iae00f0874b69d425f35b96775d6ac9634b3ade73
  • Loading branch information
anmolnar authored and phunt committed Oct 7, 2017
1 parent aa35571 commit fb10c2b
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/java/main/org/apache/zookeeper/jmx/ManagedUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public static void registerLog4jMBeans() throws JMException {
try {
// Create and Register the top level Log4J MBean
// org.apache.log4j.jmx.HierarchyDynamicMBean hdm = new org.apache.log4j.jmx.HierarchyDynamicMBean();
Object hdm = Class.forName("org.apache.log4j.jmx.HierarchyDynamicMBean").newInstance();
Object hdm = Class.forName("org.apache.log4j.jmx.HierarchyDynamicMBean").getDeclaredConstructor().newInstance();

ObjectName mbo = new ObjectName("log4j:hiearchy=default");
mbs.registerMBean(hdm, mbo);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ void handleWrite(SelectionKey k) throws IOException, CloseRequestException {
* so we've got to slice the buffer if it's too big.
*/
b = (ByteBuffer) b.slice().limit(
directBuffer.remaining());
directBuffer.remaining());
}
/*
* put() is going to modify the positions of both
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ static public ServerCnxnFactory createFactory() throws IOException {
serverCnxnFactoryName = NIOServerCnxnFactory.class.getName();
}
try {
ServerCnxnFactory serverCnxnFactory = (ServerCnxnFactory) Class.forName(serverCnxnFactoryName).newInstance();
ServerCnxnFactory serverCnxnFactory = (ServerCnxnFactory) Class.forName(serverCnxnFactoryName)
.getDeclaredConstructor().newInstance();
LOG.info("Using {} as server connection factory", serverCnxnFactoryName);
return serverCnxnFactory;
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public static void initialize() {
try {
Class<?> c = ZooKeeperServer.class.getClassLoader()
.loadClass(className);
AuthenticationProvider ap = (AuthenticationProvider) c
AuthenticationProvider ap = (AuthenticationProvider) c.getDeclaredConstructor()
.newInstance();
authenticationProviders.put(ap.getScheme(), ap);
} catch (Exception e) {
Expand Down

0 comments on commit fb10c2b

Please sign in to comment.