From 658655de04d483f4e1f29369ae3092285edc7bb3 Mon Sep 17 00:00:00 2001 From: Mark Vieira Date: Thu, 6 Jan 2022 10:28:43 -0800 Subject: [PATCH] Use Java 8 for JDBC driver target compatibility version (#82274) --- x-pack/plugin/sql/jdbc/build.gradle | 5 +++++ .../xpack/sql/jdbc/JdbcConfiguration.java | 5 ++--- x-pack/plugin/sql/sql-client/build.gradle | 5 +++++ .../elasticsearch/xpack/sql/client/StringUtils.java | 10 ++++++++++ .../org/elasticsearch/xpack/sql/client/UriUtils.java | 8 +++++--- x-pack/plugin/sql/sql-proto/build.gradle | 7 ++++++- .../xpack/sql/proto/xcontent/ErrorOnUnknown.java | 2 +- .../xpack/sql/proto/xcontent/ParsedMediaType.java | 3 ++- 8 files changed, 36 insertions(+), 9 deletions(-) diff --git a/x-pack/plugin/sql/jdbc/build.gradle b/x-pack/plugin/sql/jdbc/build.gradle index c1f7a92d8375c..c74967df7a785 100644 --- a/x-pack/plugin/sql/jdbc/build.gradle +++ b/x-pack/plugin/sql/jdbc/build.gradle @@ -16,6 +16,11 @@ dependencies { testImplementation(testArtifact(project(xpackModule('core')))) } +tasks.named("compileJava").configure { + targetCompatibility = JavaVersion.VERSION_1_8 + sourceCompatibility = JavaVersion.VERSION_1_8 +} + tasks.named("shadowJar").configure { relocate 'com.fasterxml', 'shadow.fasterxml' diff --git a/x-pack/plugin/sql/jdbc/src/main/java/org/elasticsearch/xpack/sql/jdbc/JdbcConfiguration.java b/x-pack/plugin/sql/jdbc/src/main/java/org/elasticsearch/xpack/sql/jdbc/JdbcConfiguration.java index 3c46543244e33..e12661122f3ac 100644 --- a/x-pack/plugin/sql/jdbc/src/main/java/org/elasticsearch/xpack/sql/jdbc/JdbcConfiguration.java +++ b/x-pack/plugin/sql/jdbc/src/main/java/org/elasticsearch/xpack/sql/jdbc/JdbcConfiguration.java @@ -12,7 +12,6 @@ import java.net.URI; import java.net.URLDecoder; -import java.nio.charset.StandardCharsets; import java.sql.DriverPropertyInfo; import java.time.ZoneId; import java.util.ArrayList; @@ -148,8 +147,8 @@ private static Properties parseProperties(URI uri, String u) throws JdbcSQLExcep if (args.size() != 2) { throw new JdbcSQLException("Invalid parameter [" + param + "], format needs to be key=value"); } - final String key = URLDecoder.decode(args.get(0), StandardCharsets.UTF_8).trim(); - final String val = URLDecoder.decode(args.get(1), StandardCharsets.UTF_8); + final String key = URLDecoder.decode(args.get(0), "UTF-8").trim(); + final String val = URLDecoder.decode(args.get(1), "UTF-8"); // further validation happens in the constructor (since extra properties might be specified either way) props.setProperty(key, val); } diff --git a/x-pack/plugin/sql/sql-client/build.gradle b/x-pack/plugin/sql/sql-client/build.gradle index d94fb439427b4..7fa771915c59f 100644 --- a/x-pack/plugin/sql/sql-client/build.gradle +++ b/x-pack/plugin/sql/sql-client/build.gradle @@ -12,6 +12,11 @@ dependencies { testImplementation(testArtifact(project(xpackModule('core')))) } +tasks.named("compileJava").configure { + targetCompatibility = JavaVersion.VERSION_1_8 + sourceCompatibility = JavaVersion.VERSION_1_8 +} + tasks.named('forbiddenApisMain').configure { // does not depend on core, so only jdk and http signatures should be checked replaceSignatureFiles 'jdk-signatures' diff --git a/x-pack/plugin/sql/sql-client/src/main/java/org/elasticsearch/xpack/sql/client/StringUtils.java b/x-pack/plugin/sql/sql-client/src/main/java/org/elasticsearch/xpack/sql/client/StringUtils.java index bfd565f6d09a2..a5d45f2e5b525 100644 --- a/x-pack/plugin/sql/sql-client/src/main/java/org/elasticsearch/xpack/sql/client/StringUtils.java +++ b/x-pack/plugin/sql/sql-client/src/main/java/org/elasticsearch/xpack/sql/client/StringUtils.java @@ -301,4 +301,14 @@ public static String asHexString(byte[] content, int offset, int length) { return buf.toString(); } + public static String repeatString(String in, int count) { + if (count < 0) { + throw new IllegalArgumentException("negative count: " + count); + } + StringBuffer sb = new StringBuffer(in.length() * count); + for (int i = 0; i < count; i++) { + sb.append(in); + } + return sb.toString(); + } } diff --git a/x-pack/plugin/sql/sql-client/src/main/java/org/elasticsearch/xpack/sql/client/UriUtils.java b/x-pack/plugin/sql/sql-client/src/main/java/org/elasticsearch/xpack/sql/client/UriUtils.java index b3c962531f0d5..c9a3361c267fd 100644 --- a/x-pack/plugin/sql/sql-client/src/main/java/org/elasticsearch/xpack/sql/client/UriUtils.java +++ b/x-pack/plugin/sql/sql-client/src/main/java/org/elasticsearch/xpack/sql/client/UriUtils.java @@ -15,6 +15,8 @@ import java.util.Locale; import java.util.Map; +import static org.elasticsearch.xpack.sql.client.StringUtils.repeatString; + public final class UriUtils { private UriUtils() { @@ -109,7 +111,7 @@ private static String redactAttributeInString(String string, String attrName, Ch int attrIdx = string.toLowerCase(Locale.ROOT).indexOf(needle); // note: won't catch "valid" `=password[%20]+=` cases if (attrIdx >= 0) { // ex: `...=[value]password=foo...` int attrEndIdx = attrIdx + needle.length(); - return string.substring(0, attrEndIdx) + String.valueOf(replacement).repeat(string.length() - attrEndIdx); + return string.substring(0, attrEndIdx) + repeatString(String.valueOf(replacement), string.length() - attrEndIdx); } return string; } @@ -124,7 +126,7 @@ private static void redactValueForSimilarKey( for (String k : similar) { for (Map.Entry e : attrs) { if (e.getKey().equals(k)) { - e.setValue(String.valueOf(replacement).repeat(e.getValue().length())); + e.setValue(repeatString(String.valueOf(replacement), e.getValue().length())); } } } @@ -178,7 +180,7 @@ private static String editURI(URI uri, List> fault sb.append("://"); } if (uri.getRawUserInfo() != null) { - sb.append("\0".repeat(uri.getRawUserInfo().length())); + sb.append(repeatString("\0", uri.getRawUserInfo().length())); if (uri.getHost() != null) { sb.append('@'); } diff --git a/x-pack/plugin/sql/sql-proto/build.gradle b/x-pack/plugin/sql/sql-proto/build.gradle index 2f934a5c8356c..de3f3462da85e 100644 --- a/x-pack/plugin/sql/sql-proto/build.gradle +++ b/x-pack/plugin/sql/sql-proto/build.gradle @@ -16,6 +16,11 @@ dependencies { } } +tasks.named("compileJava").configure { + targetCompatibility = JavaVersion.VERSION_1_8 + sourceCompatibility = JavaVersion.VERSION_1_8 +} + tasks.named('forbiddenApisMain').configure { //sql does not depend on server, so only jdk signatures should be checked replaceSignatureFiles 'jdk-signatures' @@ -30,4 +35,4 @@ tasks.named("thirdPartyAudit").configure { 'com.fasterxml.jackson.databind.ObjectMapper', 'com.fasterxml.jackson.databind.cfg.MapperBuilder' ) -} \ No newline at end of file +} diff --git a/x-pack/plugin/sql/sql-proto/src/main/java/org/elasticsearch/xpack/sql/proto/xcontent/ErrorOnUnknown.java b/x-pack/plugin/sql/sql-proto/src/main/java/org/elasticsearch/xpack/sql/proto/xcontent/ErrorOnUnknown.java index 374a32eedfda9..2b10b237fdfdd 100644 --- a/x-pack/plugin/sql/sql-proto/src/main/java/org/elasticsearch/xpack/sql/proto/xcontent/ErrorOnUnknown.java +++ b/x-pack/plugin/sql/sql-proto/src/main/java/org/elasticsearch/xpack/sql/proto/xcontent/ErrorOnUnknown.java @@ -33,7 +33,7 @@ public interface ErrorOnUnknown { */ int priority(); - private static ErrorOnUnknown findImplementation() { + static ErrorOnUnknown findImplementation() { ErrorOnUnknown best = new ErrorOnUnknown() { @Override public String errorMessage(String parserName, String unknownField, Iterable candidates) { diff --git a/x-pack/plugin/sql/sql-proto/src/main/java/org/elasticsearch/xpack/sql/proto/xcontent/ParsedMediaType.java b/x-pack/plugin/sql/sql-proto/src/main/java/org/elasticsearch/xpack/sql/proto/xcontent/ParsedMediaType.java index bdad2408d351d..a995c0c1ebfdd 100644 --- a/x-pack/plugin/sql/sql-proto/src/main/java/org/elasticsearch/xpack/sql/proto/xcontent/ParsedMediaType.java +++ b/x-pack/plugin/sql/sql-proto/src/main/java/org/elasticsearch/xpack/sql/proto/xcontent/ParsedMediaType.java @@ -7,6 +7,7 @@ package org.elasticsearch.xpack.sql.proto.xcontent; +import java.util.Collections; import java.util.HashMap; import java.util.Locale; import java.util.Map; @@ -34,7 +35,7 @@ private ParsedMediaType(String originalHeaderValue, String type, String subType, this.originalHeaderValue = originalHeaderValue; this.type = type; this.subType = subType; - this.parameters = Map.copyOf(parameters); + this.parameters = Collections.unmodifiableMap(parameters); } /**