You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by ta...@apache.org on 2019/05/09 05:51:40 UTC
[hadoop] branch trunk updated: HADOOP-16299. [JDK 11] Build fails
without specifying -Djavac.version=11
This is an automated email from the ASF dual-hosted git repository.
tasanuma pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/hadoop.git
The following commit(s) were added to refs/heads/trunk by this push:
new f257497 HADOOP-16299. [JDK 11] Build fails without specifying -Djavac.version=11
f257497 is described below
commit f257497b0f964c171961be4ad527983f24f9be31
Author: Akira Ajisaka <aa...@apache.org>
AuthorDate: Thu May 9 14:47:45 2019 +0900
HADOOP-16299. [JDK 11] Build fails without specifying -Djavac.version=11
Signed-off-by: Takanobu Asanuma <ta...@apache.org>
---
.../apache/hadoop/security/LdapGroupsMapping.java | 24 +++++++++++++++-------
.../hadoop/security/TestLdapGroupsMappingBase.java | 13 +++++-------
hadoop-project/pom.xml | 12 -----------
3 files changed, 22 insertions(+), 27 deletions(-)
diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/LdapGroupsMapping.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/LdapGroupsMapping.java
index 761309d..9255a84 100644
--- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/LdapGroupsMapping.java
+++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/LdapGroupsMapping.java
@@ -46,7 +46,6 @@ import javax.naming.ldap.Rdn;
import javax.naming.spi.InitialContextFactory;
import com.google.common.collect.Iterators;
-import com.sun.jndi.ldap.LdapCtxFactory;
import org.apache.hadoop.classification.InterfaceAudience;
import org.apache.hadoop.classification.InterfaceStability;
import org.apache.hadoop.conf.Configurable;
@@ -270,8 +269,9 @@ public class LdapGroupsMapping
public static final String LDAP_CTX_FACTORY_CLASS_KEY =
LDAP_CONFIG_PREFIX + ".ctx.factory.class";
- public static final Class<? extends LdapCtxFactory>
- LDAP_CTX_FACTORY_CLASS_DEFAULT = LdapCtxFactory.class;
+
+ public static final String LDAP_CTX_FACTORY_CLASS_DEFAULT =
+ "com.sun.jndi.ldap.LdapCtxFactory";
private static final Logger LOG =
LoggerFactory.getLogger(LdapGroupsMapping.class);
@@ -314,7 +314,7 @@ public class LdapGroupsMapping
private boolean useOneQuery;
private int numAttempts;
private int numAttemptsBeforeFailover;
- private Class<? extends InitialContextFactory> ldapCxtFactoryClass;
+ private String ldapCtxFactoryClassName;
/**
* Returns list of groups for a user.
@@ -633,7 +633,7 @@ public class LdapGroupsMapping
if (ctx == null) {
// Set up the initial environment for LDAP connectivity
Hashtable<String, String> env = new Hashtable<>();
- env.put(Context.INITIAL_CONTEXT_FACTORY, ldapCxtFactoryClass.getName());
+ env.put(Context.INITIAL_CONTEXT_FACTORY, ldapCtxFactoryClassName);
env.put(Context.PROVIDER_URL, currentLdapUrl);
env.put(Context.SECURITY_AUTHENTICATION, "simple");
@@ -755,8 +755,18 @@ public class LdapGroupsMapping
}
SEARCH_CONTROLS.setReturningAttributes(returningAttributes);
- ldapCxtFactoryClass = conf.getClass(LDAP_CTX_FACTORY_CLASS_KEY,
- LDAP_CTX_FACTORY_CLASS_DEFAULT, InitialContextFactory.class);
+ // LDAP_CTX_FACTORY_CLASS_DEFAULT is not open to unnamed modules
+ // in Java 11+, so the default value is set to null to avoid
+ // creating the instance for now.
+ Class<? extends InitialContextFactory> ldapCtxFactoryClass =
+ conf.getClass(LDAP_CTX_FACTORY_CLASS_KEY, null,
+ InitialContextFactory.class);
+ if (ldapCtxFactoryClass != null) {
+ ldapCtxFactoryClassName = ldapCtxFactoryClass.getName();
+ } else {
+ // The default value is set afterwards.
+ ldapCtxFactoryClassName = LDAP_CTX_FACTORY_CLASS_DEFAULT;
+ }
this.numAttempts = conf.getInt(LDAP_NUM_ATTEMPTS_KEY,
LDAP_NUM_ATTEMPTS_DEFAULT);
diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/TestLdapGroupsMappingBase.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/TestLdapGroupsMappingBase.java
index 964fe7c..bd396dd 100644
--- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/TestLdapGroupsMappingBase.java
+++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/TestLdapGroupsMappingBase.java
@@ -22,7 +22,6 @@ import static org.apache.hadoop.security.LdapGroupsMapping.LDAP_CTX_FACTORY_CLAS
import static org.apache.hadoop.security.LdapGroupsMapping.LDAP_CTX_FACTORY_CLASS_KEY;
import static org.apache.hadoop.security.LdapGroupsMapping.LDAP_URL_KEY;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -36,6 +35,7 @@ import javax.naming.directory.BasicAttributes;
import javax.naming.directory.DirContext;
import javax.naming.directory.SearchControls;
import javax.naming.directory.SearchResult;
+import javax.naming.ldap.InitialLdapContext;
import javax.naming.spi.InitialContextFactory;
import org.apache.hadoop.conf.Configuration;
@@ -235,13 +235,10 @@ public class TestLdapGroupsMappingBase {
assertEquals(expectedBindPassword, actualBindPassword);
}
if (contextToReturn == null) {
- InitialContextFactory defaultFactory = null;
- try {
- defaultFactory = LDAP_CTX_FACTORY_CLASS_DEFAULT.newInstance();
- } catch (ReflectiveOperationException e) {
- fail("Could not initialize the default factory");
- }
- return defaultFactory.getInitialContext(env);
+ Hashtable<Object, Object> newEnv = new Hashtable<>(env);
+ newEnv.put(Context.INITIAL_CONTEXT_FACTORY,
+ LDAP_CTX_FACTORY_CLASS_DEFAULT);
+ contextToReturn = new InitialLdapContext(newEnv, null);
}
return contextToReturn;
}
diff --git a/hadoop-project/pom.xml b/hadoop-project/pom.xml
index 76cf37b..9ecbb4a 100644
--- a/hadoop-project/pom.xml
+++ b/hadoop-project/pom.xml
@@ -2070,21 +2070,9 @@
<additionalOptions>
<!-- TODO: remove -html4 option to generate html5 docs when we stop supporting JDK8 -->
<additionalOption>-html4</additionalOption>
- <additionalOption>--add-exports</additionalOption>
- <additionalOption>java.naming/com.sun.jndi.ldap=ALL-UNNAMED</additionalOption>
</additionalOptions>
</configuration>
</plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-compiler-plugin</artifactId>
- <configuration>
- <compilerArgs combine.children="append">
- <arg>--add-exports</arg>
- <arg>java.naming/com.sun.jndi.ldap=ALL-UNNAMED</arg>
- </compilerArgs>
- </configuration>
- </plugin>
</plugins>
</build>
</profile>
---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org