Skip to content

Commit 28c98b0

Browse files
committed
[CALCITE-5136] Avatica build (or CI) must fail if there are deprecation warnings
Fixes applied are: * move `new URL(...)` to `new URI(...).toUrl()` * move `Assert.assertThat(...)` to `MatcherAssert.assertThat(...)` * move `ExpectedException` to `Assert.assertThrows(...)` * in all other cases either propagate the deprecation or suppress it.
1 parent b139ea7 commit 28c98b0

38 files changed

+163
-145
lines changed

.idea/vcs.xml

Lines changed: 25 additions & 25 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,7 @@ allprojects {
404404

405405
withType<JavaCompile>().configureEach {
406406
options.encoding = "UTF-8"
407+
options.compilerArgs.addAll(listOf("-Xlint:deprecation,-options", "-Werror"))
407408
}
408409
withType<Test>().configureEach {
409410
testLogging {

core/src/main/java/org/apache/calcite/avatica/BuiltInConnectionProperty.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
import org.apache.calcite.avatica.ha.ShuffledRoundRobinLBStrategy;
2020
import org.apache.calcite.avatica.remote.AvaticaHttpClientFactoryImpl;
21-
import org.apache.calcite.avatica.remote.HostnameVerificationConfigurable.HostnameVerification;
2221

2322
import org.apache.hc.core5.util.Timeout;
2423

@@ -92,8 +91,13 @@ public enum BuiltInConnectionProperty implements ConnectionProperty {
9291
/** Password for the key inside keystore */
9392
KEY_PASSWORD("key_password", Type.STRING, "", false),
9493

95-
HOSTNAME_VERIFICATION("hostname_verification", Type.ENUM, HostnameVerification.STRICT,
96-
HostnameVerification.class, false),
94+
@SuppressWarnings("deprecation")
95+
HOSTNAME_VERIFICATION("hostname_verification", Type.ENUM,
96+
org.apache.calcite.avatica.remote.
97+
HostnameVerificationConfigurable.HostnameVerification.STRICT,
98+
org.apache.calcite.avatica.remote.
99+
HostnameVerificationConfigurable.HostnameVerification.class,
100+
false),
97101

98102
TRANSPARENT_RECONNECTION("transparent_reconnection", Type.BOOLEAN, Boolean.FALSE, false),
99103

core/src/main/java/org/apache/calcite/avatica/ConnectionConfig.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
import org.apache.calcite.avatica.ha.LBStrategy;
2020
import org.apache.calcite.avatica.remote.AvaticaHttpClientFactory;
21-
import org.apache.calcite.avatica.remote.HostnameVerificationConfigurable.HostnameVerification;
2221
import org.apache.calcite.avatica.remote.Service;
2322

2423
import java.io.File;
@@ -64,7 +63,9 @@ public interface ConnectionConfig {
6463
/** @see BuiltInConnectionProperty#KEY_PASSWORD */
6564
String keyPassword();
6665
/** @see BuiltInConnectionProperty#HOSTNAME_VERIFICATION */
67-
HostnameVerification hostnameVerification();
66+
@SuppressWarnings("deprecation")
67+
org.apache.calcite.avatica.remote.
68+
HostnameVerificationConfigurable.HostnameVerification hostnameVerification();
6869
/** @see BuiltInConnectionProperty#TRANSPARENT_RECONNECTION */
6970
boolean transparentReconnectionEnabled();
7071
/** @see BuiltInConnectionProperty#FETCH_SIZE */

core/src/main/java/org/apache/calcite/avatica/ConnectionConfigImpl.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
import org.apache.calcite.avatica.ha.LBStrategy;
2020
import org.apache.calcite.avatica.remote.AvaticaHttpClientFactory;
21-
import org.apache.calcite.avatica.remote.HostnameVerificationConfigurable.HostnameVerification;
2221
import org.apache.calcite.avatica.remote.Service;
2322

2423
import java.io.File;
@@ -130,9 +129,12 @@ public String keyPassword() {
130129

131130
}
132131

133-
public HostnameVerification hostnameVerification() {
132+
@SuppressWarnings("deprecation")
133+
public org.apache.calcite.avatica.remote.
134+
HostnameVerificationConfigurable.HostnameVerification hostnameVerification() {
134135
return BuiltInConnectionProperty.HOSTNAME_VERIFICATION.wrap(properties)
135-
.getEnum(HostnameVerification.class);
136+
.getEnum(org.apache.calcite.avatica.remote.
137+
HostnameVerificationConfigurable.HostnameVerification.class);
136138
}
137139

138140
@Override public boolean transparentReconnectionEnabled() {

core/src/main/java/org/apache/calcite/avatica/remote/AvaticaCommonsHttpClientImpl.java

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424
import org.apache.hc.client5.http.auth.AuthScope;
2525
import org.apache.hc.client5.http.auth.Credentials;
2626
import org.apache.hc.client5.http.auth.CredentialsProvider;
27-
import org.apache.hc.client5.http.auth.KerberosConfig;
28-
import org.apache.hc.client5.http.auth.KerberosCredentials;
2927
import org.apache.hc.client5.http.auth.StandardAuthScheme;
3028
import org.apache.hc.client5.http.auth.UsernamePasswordCredentials;
3129
import org.apache.hc.client5.http.classic.methods.HttpPost;
@@ -34,7 +32,6 @@
3432
import org.apache.hc.client5.http.impl.auth.BasicCredentialsProvider;
3533
import org.apache.hc.client5.http.impl.auth.BasicSchemeFactory;
3634
import org.apache.hc.client5.http.impl.auth.DigestSchemeFactory;
37-
import org.apache.hc.client5.http.impl.auth.SPNegoSchemeFactory;
3835
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
3936
import org.apache.hc.client5.http.impl.classic.HttpClientBuilder;
4037
import org.apache.hc.client5.http.impl.classic.HttpClients;
@@ -78,8 +75,10 @@ public class AvaticaCommonsHttpClientImpl implements AvaticaHttpClient, HttpClie
7875
private static final boolean USE_CANONICAL_HOSTNAME = Boolean
7976
.parseBoolean(System.getProperty("avatica.http.spnego.use_canonical_hostname", "true"));
8077
private static final boolean STRIP_PORT_ON_SERVER_LOOKUP = true;
81-
private static final KerberosConfig KERBEROS_CONFIG =
82-
KerberosConfig.custom().setStripPort(STRIP_PORT_ON_SERVER_LOOKUP)
78+
@SuppressWarnings("deprecation")
79+
private static final org.apache.hc.client5.http.auth.KerberosConfig KERBEROS_CONFIG =
80+
org.apache.hc.client5.http.auth.KerberosConfig.custom()
81+
.setStripPort(STRIP_PORT_ON_SERVER_LOOKUP)
8382
.setUseCanonicalHostname(USE_CANONICAL_HOSTNAME)
8483
.build();
8584
private static AuthScope anyAuthScope = new AuthScope(null, -1);
@@ -98,10 +97,15 @@ public class AvaticaCommonsHttpClientImpl implements AvaticaHttpClient, HttpClie
9897
protected long connectTimeout;
9998
protected long responseTimeout;
10099

100+
@Deprecated
101101
public AvaticaCommonsHttpClientImpl(URL url) {
102102
this.uri = toURI(Objects.requireNonNull(url));
103103
}
104104

105+
public AvaticaCommonsHttpClientImpl(URI uri) {
106+
this.uri = uri;
107+
}
108+
105109
protected void initializeClient(PoolingHttpClientConnectionManager pool,
106110
ConnectionConfig config) {
107111
this.authCache = new BasicAuthCache();
@@ -128,6 +132,7 @@ protected void initializeClient(PoolingHttpClientConnectionManager pool,
128132
}
129133

130134
// This is needed because we initialize the client object too early.
135+
@SuppressWarnings("deprecation")
131136
private RequestConfig createRequestConfig() {
132137
RequestConfig.Builder requestConfigBuilder = RequestConfig.custom();
133138
requestConfigBuilder
@@ -225,19 +230,23 @@ ClassicHttpResponse executeOpen(HttpHost httpHost, HttpPost post, HttpClientCont
225230
context.setRequestConfig(createRequestConfig());
226231
}
227232

233+
@SuppressWarnings("deprecation")
228234
@Override public void setGSSCredential(GSSCredential credential) {
229235

230236
this.authRegistry = RegistryBuilder.<AuthSchemeFactory>create()
231237
.register(StandardAuthScheme.SPNEGO,
232-
new SPNegoSchemeFactory(KERBEROS_CONFIG, SystemDefaultDnsResolver.INSTANCE))
238+
new org.apache.hc.client5.http.impl.auth.SPNegoSchemeFactory(
239+
KERBEROS_CONFIG,
240+
SystemDefaultDnsResolver.INSTANCE))
233241
.build();
234242

235243
this.credentialsProvider = new BasicCredentialsProvider();
236244
if (null != credential) {
237245
// Non-null credential should be used directly with KerberosCredentials.
238246
// This is never set by the JDBC driver, nor the tests
239247
((BasicCredentialsProvider) this.credentialsProvider)
240-
.setCredentials(anyAuthScope, new KerberosCredentials(credential));
248+
.setCredentials(anyAuthScope,
249+
new org.apache.hc.client5.http.auth.KerberosCredentials(credential));
241250
} else {
242251
// A null credential implies that the user is logged in via JAAS using the
243252
// java.security.auth.login.config system property
@@ -255,6 +264,7 @@ ClassicHttpResponse executeOpen(HttpHost httpHost, HttpPost post, HttpClientCont
255264
private static class EmptyCredentials implements Credentials {
256265
public static final EmptyCredentials INSTANCE = new EmptyCredentials();
257266

267+
@Deprecated
258268
@Override public char[] getPassword() {
259269
return null;
260270
}

core/src/main/java/org/apache/calcite/avatica/remote/AvaticaHttpClientFactoryImpl.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public static AvaticaHttpClientFactoryImpl getInstance() {
5353
return INSTANCE;
5454
}
5555

56+
@SuppressWarnings("deprecation")
5657
@Override public AvaticaHttpClient getClient(URL url, ConnectionConfig config,
5758
KerberosConnection kerberosUtil) {
5859
String className = config.httpClientClass();

core/src/main/java/org/apache/calcite/avatica/remote/CommonsHttpClientPoolCache.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package org.apache.calcite.avatica.remote;
1818

1919
import org.apache.calcite.avatica.ConnectionConfig;
20-
import org.apache.calcite.avatica.remote.HostnameVerificationConfigurable.HostnameVerification;
2120

2221
import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager;
2322
import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManagerBuilder;
@@ -128,11 +127,15 @@ private static void loadTrustStore(SSLContextBuilder sslContextBuilder, Connecti
128127
* @throws IllegalArgumentException if the provided verification cannot be
129128
* handled.
130129
*/
131-
private static HostnameVerifier getHostnameVerifier(HostnameVerification verification) {
130+
@SuppressWarnings("deprecation")
131+
private static HostnameVerifier getHostnameVerifier(
132+
org.apache.calcite.avatica.remote.
133+
HostnameVerificationConfigurable.HostnameVerification verification) {
132134
// Normally, the configuration logic would give us a default of STRICT if it was
133135
// not provided by the user. It's easy for us to do a double-check.
134136
if (verification == null) {
135-
verification = HostnameVerification.STRICT;
137+
verification = org.apache.calcite.avatica.remote.
138+
HostnameVerificationConfigurable.HostnameVerification.STRICT;
136139
}
137140
switch (verification) {
138141
case STRICT:

core/src/main/java/org/apache/calcite/avatica/remote/Driver.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
import org.slf4j.LoggerFactory;
2929

3030
import java.net.MalformedURLException;
31+
import java.net.URI;
32+
import java.net.URISyntaxException;
3133
import java.net.URL;
3234
import java.sql.Connection;
3335
import java.sql.SQLException;
@@ -156,8 +158,8 @@ AvaticaHttpClient getHttpClient(AvaticaConnection connection, ConnectionConfig c
156158
urlStr = config.url();
157159
}
158160
try {
159-
url = new URL(urlStr);
160-
} catch (MalformedURLException e) {
161+
url = new URI(urlStr).toURL();
162+
} catch (MalformedURLException | URISyntaxException e) {
161163
throw new RuntimeException(e);
162164
}
163165

core/src/main/java/org/apache/calcite/avatica/util/Sources.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ public static Source file(File baseDirectory, String fileName) {
5959

6060
public static Source url(String url) {
6161
try {
62-
return of(new URL(url));
63-
} catch (MalformedURLException | IllegalArgumentException e) {
62+
return of(new URI(url).toURL());
63+
} catch (MalformedURLException | IllegalArgumentException | URISyntaxException e) {
6464
throw new RuntimeException("Malformed URL: '" + url + "'", e);
6565
}
6666
}
@@ -133,11 +133,7 @@ private static URL fileToUrl(File file) {
133133
filePath += "/";
134134
}
135135
try {
136-
// We need to encode path. For instance, " " should become "%20"
137-
// That is why java.net.URLEncoder.encode(java.lang.String, java.lang.String) is not
138-
// suitable because it replaces " " with "+".
139-
String encodedPath = new URI(null, null, filePath, null).getRawPath();
140-
return new URL("file", null, 0, encodedPath);
136+
return new URI("file", filePath, null).toURL();
141137
} catch (MalformedURLException | URISyntaxException e) {
142138
throw new IllegalArgumentException("Unable to create URL for file " + filePath, e);
143139
}

0 commit comments

Comments
 (0)