Skip to content

Commit

Permalink
HADOOP-16299. [JDK 11] Build fails without specifying -Djavac.version=11
Browse files Browse the repository at this point in the history
Signed-off-by: Takanobu Asanuma <[email protected]>
  • Loading branch information
aajisaka authored and tasanuma committed May 9, 2019
1 parent 0c5fa2e commit f257497
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -633,7 +633,7 @@ private DirContext getDirContext() throws NamingException {
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");

Expand Down Expand Up @@ -755,8 +755,18 @@ public synchronized void setConf(Configuration conf) {
}
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
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;

Expand All @@ -36,6 +35,7 @@
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;
Expand Down Expand Up @@ -235,13 +235,10 @@ public Context getInitialContext(Hashtable<?, ?> env)
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;
}
Expand Down
12 changes: 0 additions & 12 deletions hadoop-project/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down

0 comments on commit f257497

Please sign in to comment.