Skip to content

Commit 468177b

Browse files
amahusseinHarshitGupta11
authored andcommitted
HADOOP-17123. remove guava Preconditions from Hadoop-common-project modules (apache#3543)
1 parent fe39d06 commit 468177b

File tree

143 files changed

+186
-200
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

143 files changed

+186
-200
lines changed

hadoop-common-project/hadoop-auth/pom.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,10 +269,12 @@
269269
<rules>
270270
<restrictImports implementation="de.skuzzle.enforcer.restrictimports.rule.RestrictImports">
271271
<includeTestCode>true</includeTestCode>
272-
<reason>Use hadoop-common provided VisibleForTesting rather than the one provided by Guava</reason>
272+
<reason>Use hadoop-common provided implementations rather than the one provided by Guava</reason>
273273
<bannedImports>
274274
<bannedImport>org.apache.hadoop.thirdparty.com.google.common.annotations.VisibleForTesting</bannedImport>
275275
<bannedImport>com.google.common.annotations.VisibleForTesting</bannedImport>
276+
<bannedImport>org.apache.hadoop.thirdparty.com.google.common.base.Preconditions</bannedImport>
277+
<bannedImport>com.google.common.base.Preconditions</bannedImport>
276278
</bannedImports>
277279
</restrictImports>
278280
</rules>

hadoop-common-project/hadoop-auth/src/main/java/org/apache/hadoop/security/authentication/server/AuthenticationHandlerUtil.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020

2121
import java.util.Locale;
2222

23-
import org.apache.hadoop.thirdparty.com.google.common.base.Preconditions;
24-
2523
/**
2624
* This is a utility class designed to provide functionality related to
2725
* {@link AuthenticationHandler}.
@@ -44,8 +42,10 @@ private AuthenticationHandlerUtil() {
4442
* @return an instance of AuthenticationHandler implementation.
4543
*/
4644
public static String getAuthenticationHandlerClassName(String authHandler) {
47-
String handlerName =
48-
Preconditions.checkNotNull(authHandler).toLowerCase(Locale.ENGLISH);
45+
if (authHandler == null) {
46+
throw new NullPointerException();
47+
}
48+
String handlerName = authHandler.toLowerCase(Locale.ENGLISH);
4949

5050
String authHandlerClassName = null;
5151

@@ -98,8 +98,14 @@ public static String checkAuthScheme(String scheme) {
9898
* specified authentication scheme false Otherwise.
9999
*/
100100
public static boolean matchAuthScheme(String scheme, String auth) {
101-
scheme = Preconditions.checkNotNull(scheme).trim();
102-
auth = Preconditions.checkNotNull(auth).trim();
101+
if (scheme == null) {
102+
throw new NullPointerException();
103+
}
104+
scheme = scheme.trim();
105+
if (auth == null) {
106+
throw new NullPointerException();
107+
}
108+
auth = auth.trim();
103109
return auth.regionMatches(true, 0, scheme, 0, scheme.length());
104110
}
105111
}

hadoop-common-project/hadoop-auth/src/main/java/org/apache/hadoop/security/authentication/server/LdapAuthenticationHandler.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
import org.slf4j.LoggerFactory;
4040

4141
import org.apache.hadoop.classification.VisibleForTesting;
42-
import org.apache.hadoop.thirdparty.com.google.common.base.Preconditions;
4342

4443
/**
4544
* The {@link LdapAuthenticationHandler} implements the BASIC authentication
@@ -144,15 +143,20 @@ public void init(Properties config) throws ServletException {
144143
this.enableStartTls =
145144
Boolean.valueOf(config.getProperty(ENABLE_START_TLS, "false"));
146145

147-
Preconditions
148-
.checkNotNull(this.providerUrl, "The LDAP URI can not be null");
149-
Preconditions.checkArgument((this.baseDN == null)
150-
^ (this.ldapDomain == null),
151-
"Either LDAP base DN or LDAP domain value needs to be specified");
146+
if (this.providerUrl == null) {
147+
throw new NullPointerException("The LDAP URI can not be null");
148+
}
149+
if (!((this.baseDN == null)
150+
^ (this.ldapDomain == null))) {
151+
throw new IllegalArgumentException(
152+
"Either LDAP base DN or LDAP domain value needs to be specified");
153+
}
152154
if (this.enableStartTls) {
153155
String tmp = this.providerUrl.toLowerCase();
154-
Preconditions.checkArgument(!tmp.startsWith("ldaps"),
155-
"Can not use ldaps and StartTLS option at the same time");
156+
if (tmp.startsWith("ldaps")) {
157+
throw new IllegalArgumentException(
158+
"Can not use ldaps and StartTLS option at the same time");
159+
}
156160
}
157161
}
158162

hadoop-common-project/hadoop-auth/src/main/java/org/apache/hadoop/security/authentication/server/MultiSchemeAuthenticationHandler.java

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import org.slf4j.Logger;
3131
import org.slf4j.LoggerFactory;
3232

33-
import org.apache.hadoop.thirdparty.com.google.common.base.Preconditions;
3433
import org.apache.hadoop.thirdparty.com.google.common.base.Splitter;
3534

3635
/**
@@ -114,10 +113,10 @@ public void init(Properties config) throws ServletException {
114113
}
115114

116115
this.types.clear();
117-
118-
String schemesProperty =
119-
Preconditions.checkNotNull(config.getProperty(SCHEMES_PROPERTY),
120-
"%s system property is not specified.", SCHEMES_PROPERTY);
116+
if (config.getProperty(SCHEMES_PROPERTY) == null) {
117+
throw new NullPointerException(SCHEMES_PROPERTY + " system property is not specified.");
118+
}
119+
String schemesProperty = config.getProperty(SCHEMES_PROPERTY);
121120
for (String scheme : STR_SPLITTER.split(schemesProperty)) {
122121
scheme = AuthenticationHandlerUtil.checkAuthScheme(scheme);
123122
if (schemeToAuthHandlerMapping.containsKey(scheme)) {
@@ -128,8 +127,10 @@ public void init(Properties config) throws ServletException {
128127
String authHandlerPropName =
129128
String.format(AUTH_HANDLER_PROPERTY, scheme).toLowerCase();
130129
String authHandlerName = config.getProperty(authHandlerPropName);
131-
Preconditions.checkNotNull(authHandlerName,
132-
"No auth handler configured for scheme %s.", scheme);
130+
if (authHandlerName == null) {
131+
throw new NullPointerException(
132+
"No auth handler configured for scheme " + scheme);
133+
}
133134

134135
String authHandlerClassName =
135136
AuthenticationHandlerUtil
@@ -145,7 +146,9 @@ public void init(Properties config) throws ServletException {
145146
protected AuthenticationHandler initializeAuthHandler(
146147
String authHandlerClassName, Properties config) throws ServletException {
147148
try {
148-
Preconditions.checkNotNull(authHandlerClassName);
149+
if (authHandlerClassName == null) {
150+
throw new NullPointerException();
151+
}
149152
logger.debug("Initializing Authentication handler of type "
150153
+ authHandlerClassName);
151154
Class<?> klass =

hadoop-common-project/hadoop-common/pom.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -672,10 +672,12 @@
672672
<rules>
673673
<restrictImports implementation="de.skuzzle.enforcer.restrictimports.rule.RestrictImports">
674674
<includeTestCode>true</includeTestCode>
675-
<reason>Use hadoop-common provided VisibleForTesting rather than the one provided by Guava</reason>
675+
<reason>Use hadoop-common provided implementations rather than the one provided by Guava</reason>
676676
<bannedImports>
677677
<bannedImport>org.apache.hadoop.thirdparty.com.google.common.annotations.VisibleForTesting</bannedImport>
678678
<bannedImport>com.google.common.annotations.VisibleForTesting</bannedImport>
679+
<bannedImport>org.apache.hadoop.thirdparty.com.google.common.base.Preconditions</bannedImport>
680+
<bannedImport>com.google.common.base.Preconditions</bannedImport>
679681
</bannedImports>
680682
</restrictImports>
681683
</rules>

hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/conf/Configuration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@
107107
import org.w3c.dom.Document;
108108
import org.w3c.dom.Element;
109109

110-
import org.apache.hadoop.thirdparty.com.google.common.base.Preconditions;
110+
import org.apache.hadoop.util.Preconditions;
111111
import org.apache.hadoop.thirdparty.com.google.common.base.Strings;
112112

113113
import static org.apache.commons.lang3.StringUtils.isBlank;

hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/conf/ReconfigurableBase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
package org.apache.hadoop.conf;
2020

2121
import org.apache.hadoop.classification.VisibleForTesting;
22-
import org.apache.hadoop.thirdparty.com.google.common.base.Preconditions;
22+
import org.apache.hadoop.util.Preconditions;
2323
import org.apache.hadoop.thirdparty.com.google.common.collect.Maps;
2424
import org.apache.hadoop.util.Time;
2525
import org.apache.hadoop.conf.ReconfigurationUtil.PropertyChange;

hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/crypto/CryptoInputStream.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
import java.util.Queue;
3131
import java.util.concurrent.ConcurrentLinkedQueue;
3232

33-
import org.apache.hadoop.thirdparty.com.google.common.base.Preconditions;
33+
import org.apache.hadoop.util.Preconditions;
3434
import org.apache.hadoop.classification.InterfaceAudience;
3535
import org.apache.hadoop.classification.InterfaceStability;
3636
import org.apache.hadoop.fs.ByteBufferPositionedReadable;

hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/crypto/CryptoOutputStream.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@
3131
import org.apache.hadoop.fs.statistics.IOStatistics;
3232
import org.apache.hadoop.fs.statistics.IOStatisticsSource;
3333
import org.apache.hadoop.fs.impl.StoreImplementationUtils;
34-
35-
import org.apache.hadoop.thirdparty.com.google.common.base.Preconditions;
34+
import org.apache.hadoop.util.Preconditions;
3635

3736
import static org.apache.hadoop.fs.statistics.IOStatisticsSupport.retrieveIOStatistics;
3837

hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/crypto/CryptoStreamUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
import org.apache.hadoop.conf.Configuration;
2929
import org.apache.hadoop.fs.Seekable;
3030
import org.apache.hadoop.util.CleanerUtil;
31+
import org.apache.hadoop.util.Preconditions;
3132

32-
import org.apache.hadoop.thirdparty.com.google.common.base.Preconditions;
3333
import org.slf4j.Logger;
3434
import org.slf4j.LoggerFactory;
3535

0 commit comments

Comments
 (0)