Skip to content

Commit

Permalink
Use Java 8 for JDBC driver target compatibility version (elastic#82274)
Browse files Browse the repository at this point in the history
  • Loading branch information
mark-vieira committed Jan 6, 2022
1 parent 7f212dc commit 658655d
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 9 deletions.
5 changes: 5 additions & 0 deletions x-pack/plugin/sql/jdbc/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down
5 changes: 5 additions & 0 deletions x-pack/plugin/sql/sql-client/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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() {

Expand Down Expand Up @@ -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;
}
Expand All @@ -124,7 +126,7 @@ private static void redactValueForSimilarKey(
for (String k : similar) {
for (Map.Entry<String, String> 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()));
}
}
}
Expand Down Expand Up @@ -178,7 +180,7 @@ private static String editURI(URI uri, List<Map.Entry<Integer, Character>> 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('@');
}
Expand Down
7 changes: 6 additions & 1 deletion x-pack/plugin/sql/sql-proto/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -30,4 +35,4 @@ tasks.named("thirdPartyAudit").configure {
'com.fasterxml.jackson.databind.ObjectMapper',
'com.fasterxml.jackson.databind.cfg.MapperBuilder'
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> candidates) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

/**
Expand Down

0 comments on commit 658655d

Please sign in to comment.