This is an automated email from the ASF dual-hosted git repository. jhyde pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/calcite-avatica.git
commit 4cee17299766a97a2ba39901ad2639ee0d332e84 Author: Richard Antal <[email protected]> AuthorDate: Thu Nov 3 15:59:04 2022 +0100 [CALCITE-5329] Upgrade Checkstyle version from 6.18 to 10.3.2 Close apache/calcite-avatica#191 --- .github/workflows/main.yml | 4 +- build.gradle.kts | 1 - .../org/apache/calcite/avatica/AvaticaUtils.java | 20 +++++++- .../org/apache/calcite/avatica/ColumnMetaData.java | 24 +++++----- .../calcite/avatica/ConnectStringParser.java | 4 +- .../org/apache/calcite/avatica/DriverVersion.java | 2 +- .../apache/calcite/avatica/remote/JsonHandler.java | 4 +- .../calcite/avatica/remote/LocalService.java | 10 ++-- .../calcite/avatica/remote/ProtobufHandler.java | 4 +- .../avatica/remote/RemoteProtobufService.java | 5 +- .../calcite/avatica/remote/RemoteService.java | 4 +- .../calcite/avatica/util/AbstractCursor.java | 5 +- .../org/apache/calcite/avatica/util/Base64.java | 33 ++++++++----- .../apache/calcite/avatica/util/ByteString.java | 2 +- .../org/apache/calcite/avatica/util/Cursor.java | 2 +- .../apache/calcite/avatica/util/DateTimeUtils.java | 4 +- .../org/apache/calcite/avatica/util/Spaces.java | 2 +- .../remote/AvaticaCommonsHttpClientImplTest.java | 6 ++- .../calcite/avatica/remote/TypedValueTest.java | 5 +- gradle.properties | 4 +- .../org/apache/calcite/avatica/metrics/Timer.java | 2 +- .../calcite/avatica/server/AvaticaJsonHandler.java | 4 +- .../avatica/server/AvaticaProtobufHandler.java | 2 +- .../apache/calcite/avatica/RemoteDriverTest.java | 4 +- .../avatica/remote/AlternatingRemoteMetaTest.java | 4 +- .../calcite/avatica/remote/RemoteMetaTest.java | 24 +++++----- .../avatica/server/AbstractAvaticaHandlerTest.java | 4 +- .../server/HttpServerSpnegoWithoutJaasTest.java | 3 +- src/main/config/checkstyle/checker.xml | 55 ++++++++++------------ 29 files changed, 138 insertions(+), 109 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 36db450e4..37651f091 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -58,7 +58,7 @@ jobs: fetch-depth: 50 - name: 'Test' run: | - ./gradlew --no-parallel --no-daemon build javadoc + ./gradlew --no-parallel --no-daemon build javadoc -Pcheckstyle.version=9.3 linux-jdk8-avatica: name: 'Linux (JDK 8), Avatica main' @@ -74,7 +74,7 @@ jobs: fetch-depth: 50 - name: 'Install Avatica to Maven Local' run: | - ./gradlew publishToMavenLocal -Pcalcite.avatica.version=1.0.0-dev-main -PskipJavadoc + ./gradlew publishToMavenLocal -Pcalcite.avatica.version=1.0.0-dev-main -PskipJavadoc -Pcheckstyle.version=9.3 - name: 'Test Calcite' run: | git clone --depth 100 https://github.com/apache/calcite.git ../calcite diff --git a/build.gradle.kts b/build.gradle.kts index 4ef997542..88753b56e 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -208,7 +208,6 @@ allprojects { apply<CheckstylePlugin>() dependencies { checkstyle("com.puppycrawl.tools:checkstyle:${"checkstyle".v}") - checkstyle("net.hydromatic:toolbox:${"hydromatic-toolbox".v}") } checkstyle { // Current one is ~8.8 diff --git a/core/src/main/java/org/apache/calcite/avatica/AvaticaUtils.java b/core/src/main/java/org/apache/calcite/avatica/AvaticaUtils.java index 000ebd0d3..ef27e8269 100644 --- a/core/src/main/java/org/apache/calcite/avatica/AvaticaUtils.java +++ b/core/src/main/java/org/apache/calcite/avatica/AvaticaUtils.java @@ -20,10 +20,12 @@ import org.apache.calcite.avatica.util.UnsynchronizedBuffer; import java.io.IOException; import java.io.InputStream; +import java.io.UnsupportedEncodingException; import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandles; import java.lang.invoke.MethodType; import java.lang.reflect.Field; +import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.sql.PreparedStatement; import java.sql.SQLException; @@ -288,7 +290,7 @@ public class AvaticaUtils { throws IOException { // Variant that lets us use a pooled Buffer final byte[] bytes = _readFully(inputStream, buffer); - return new String(bytes, 0, bytes.length, StandardCharsets.UTF_8); + return AvaticaUtils.newStringUtf8(bytes); } /** Reads the contents of an input stream and returns as a string. */ @@ -474,6 +476,22 @@ public class AvaticaUtils { } return longs; } + + public static String newStringUtf8(final byte[] bytes) { + return newString(bytes, StandardCharsets.UTF_8); + } + +//CHECKSTYLE: OFF + public static String newString(final byte[] bytes, final Charset charset) { + return new String(bytes, charset); + } + + public static String newString(final byte[] bytes, final String charsetName) + throws UnsupportedEncodingException { + return new String(bytes, charsetName); + } +//CHECKSTYLE:ON + } // End AvaticaUtils.java diff --git a/core/src/main/java/org/apache/calcite/avatica/ColumnMetaData.java b/core/src/main/java/org/apache/calcite/avatica/ColumnMetaData.java index 4c5ed11b4..2c5d55b71 100644 --- a/core/src/main/java/org/apache/calcite/avatica/ColumnMetaData.java +++ b/core/src/main/java/org/apache/calcite/avatica/ColumnMetaData.java @@ -138,18 +138,18 @@ public class ColumnMetaData { // Primitive fields (can't be null) builder.setOrdinal(ordinal) - .setAutoIncrement(autoIncrement) - .setCaseSensitive(caseSensitive) - .setSearchable(searchable) - .setCurrency(currency) - .setNullable(nullable) - .setSigned(signed) - .setDisplaySize(displaySize) - .setPrecision(precision) - .setScale(scale) - .setReadOnly(readOnly) - .setWritable(writable) - .setDefinitelyWritable(definitelyWritable); + .setAutoIncrement(autoIncrement) + .setCaseSensitive(caseSensitive) + .setSearchable(searchable) + .setCurrency(currency) + .setNullable(nullable) + .setSigned(signed) + .setDisplaySize(displaySize) + .setPrecision(precision) + .setScale(scale) + .setReadOnly(readOnly) + .setWritable(writable) + .setDefinitelyWritable(definitelyWritable); // Potentially null fields if (null != label) { diff --git a/core/src/main/java/org/apache/calcite/avatica/ConnectStringParser.java b/core/src/main/java/org/apache/calcite/avatica/ConnectStringParser.java index 9efbcf113..b4b2562b7 100644 --- a/core/src/main/java/org/apache/calcite/avatica/ConnectStringParser.java +++ b/core/src/main/java/org/apache/calcite/avatica/ConnectStringParser.java @@ -174,7 +174,7 @@ public class ConnectStringParser { switch (c) { case '=': i++; - if ((i < n) && ((c = s.charAt(i)) == '=')) { + if (i < n && (c = s.charAt(i)) == '=') { // doubled equals sign; take one of them, and carry on i++; nameBuf.append(c); @@ -216,7 +216,7 @@ public class ConnectStringParser { return ""; } } - if ((c == '"') || (c == '\'')) { + if (c == '"' || c == '\'') { String value = parseQuoted(c); // skip over trailing white space diff --git a/core/src/main/java/org/apache/calcite/avatica/DriverVersion.java b/core/src/main/java/org/apache/calcite/avatica/DriverVersion.java index 7c97778b1..c84dbb0db 100644 --- a/core/src/main/java/org/apache/calcite/avatica/DriverVersion.java +++ b/core/src/main/java/org/apache/calcite/avatica/DriverVersion.java @@ -96,7 +96,7 @@ public class DriverVersion { int minorVersion = 0; int databaseMajorVersion = 0; int databaseMinorVersion = 0; - try (final InputStream inStream = + try (InputStream inStream = driverClass.getClassLoader().getResourceAsStream(resourceName)) { if (inStream != null) { final Properties properties = new Properties(); diff --git a/core/src/main/java/org/apache/calcite/avatica/remote/JsonHandler.java b/core/src/main/java/org/apache/calcite/avatica/remote/JsonHandler.java index fd57078f4..9e2e0fc94 100644 --- a/core/src/main/java/org/apache/calcite/avatica/remote/JsonHandler.java +++ b/core/src/main/java/org/apache/calcite/avatica/remote/JsonHandler.java @@ -53,7 +53,7 @@ public class JsonHandler extends AbstractHandler<String> { } @Override Request decode(String request) throws IOException { - try (final Context ctx = serializationTimer.start()) { + try (Context ctx = serializationTimer.start()) { return MAPPER.readValue(request, Service.Request.class); } } @@ -65,7 +65,7 @@ public class JsonHandler extends AbstractHandler<String> { * @return A JSON string. */ @Override String encode(Response response) throws IOException { - try (final Context ctx = serializationTimer.start()) { + try (Context ctx = serializationTimer.start()) { final StringWriter w = new StringWriter(); MAPPER.writeValue(w, response); return w.toString(); diff --git a/core/src/main/java/org/apache/calcite/avatica/remote/LocalService.java b/core/src/main/java/org/apache/calcite/avatica/remote/LocalService.java index df7ed4740..f125973d7 100644 --- a/core/src/main/java/org/apache/calcite/avatica/remote/LocalService.java +++ b/core/src/main/java/org/apache/calcite/avatica/remote/LocalService.java @@ -194,7 +194,7 @@ public class LocalService implements Service { } public PrepareResponse apply(PrepareRequest request) { - try (final Context ignore = prepareTimer.start()) { + try (Context ignore = prepareTimer.start()) { final Meta.ConnectionHandle ch = new Meta.ConnectionHandle(request.connectionId); final Meta.StatementHandle h = @@ -204,7 +204,7 @@ public class LocalService implements Service { } public ExecuteResponse apply(PrepareAndExecuteRequest request) { - try (final Context ignore = prepareAndExecuteTimer.start()) { + try (Context ignore = prepareAndExecuteTimer.start()) { final Meta.StatementHandle sh = new Meta.StatementHandle(request.connectionId, request.statementId, null); try { @@ -255,7 +255,7 @@ public class LocalService implements Service { } public ExecuteResponse apply(ExecuteRequest request) { - try (final Context ignore = executeTimer.start()) { + try (Context ignore = executeTimer.start()) { try { final Meta.ExecuteResult executeResult = meta.execute(request.statementHandle, request.parameterValues, AvaticaUtils.toSaturatedInt(request.maxRowCount)); @@ -300,7 +300,7 @@ public class LocalService implements Service { } public ConnectionSyncResponse apply(ConnectionSyncRequest request) { - try (final Context ignore = connectionSyncTimer.start()) { + try (Context ignore = connectionSyncTimer.start()) { final Meta.ConnectionHandle ch = new Meta.ConnectionHandle(request.connectionId); final Meta.ConnectionProperties connProps = @@ -332,7 +332,7 @@ public class LocalService implements Service { } public CommitResponse apply(CommitRequest request) { - try (final Context ignore = commitTimer.start()) { + try (Context ignore = commitTimer.start()) { meta.commit(new Meta.ConnectionHandle(request.connectionId)); // If commit() errors, let the ErrorResponse be sent back via an uncaught Exception. diff --git a/core/src/main/java/org/apache/calcite/avatica/remote/ProtobufHandler.java b/core/src/main/java/org/apache/calcite/avatica/remote/ProtobufHandler.java index 89e380e6a..4ff9bb480 100644 --- a/core/src/main/java/org/apache/calcite/avatica/remote/ProtobufHandler.java +++ b/core/src/main/java/org/apache/calcite/avatica/remote/ProtobufHandler.java @@ -47,13 +47,13 @@ public class ProtobufHandler extends AbstractHandler<byte[]> { } @Override Service.Request decode(byte[] serializedRequest) throws IOException { - try (final Context ctx = serializationTimer.start()) { + try (Context ctx = serializationTimer.start()) { return translation.parseRequest(serializedRequest); } } @Override byte[] encode(Response response) throws IOException { - try (final Context ctx = serializationTimer.start()) { + try (Context ctx = serializationTimer.start()) { return translation.serializeResponse(response); } } diff --git a/core/src/main/java/org/apache/calcite/avatica/remote/RemoteProtobufService.java b/core/src/main/java/org/apache/calcite/avatica/remote/RemoteProtobufService.java index f62e994d5..bfa7b8ee4 100644 --- a/core/src/main/java/org/apache/calcite/avatica/remote/RemoteProtobufService.java +++ b/core/src/main/java/org/apache/calcite/avatica/remote/RemoteProtobufService.java @@ -16,11 +16,12 @@ */ package org.apache.calcite.avatica.remote; +import org.apache.calcite.avatica.AvaticaUtils; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.IOException; -import java.nio.charset.StandardCharsets; /** * ProtobufService implementation that queries against a remote implementation, using @@ -52,7 +53,7 @@ public class RemoteProtobufService extends ProtobufService { resp = translation.parseResponse(response); } catch (IOException e) { LOG.debug("Failed to deserialize reponse to {}. '{}'", request, - new String(response, StandardCharsets.UTF_8)); + AvaticaUtils.newStringUtf8(response)); // Not a protobuf that we could parse. throw new RuntimeException(e); } diff --git a/core/src/main/java/org/apache/calcite/avatica/remote/RemoteService.java b/core/src/main/java/org/apache/calcite/avatica/remote/RemoteService.java index d4828b558..dde27461a 100644 --- a/core/src/main/java/org/apache/calcite/avatica/remote/RemoteService.java +++ b/core/src/main/java/org/apache/calcite/avatica/remote/RemoteService.java @@ -16,6 +16,8 @@ */ package org.apache.calcite.avatica.remote; +import org.apache.calcite.avatica.AvaticaUtils; + import java.nio.charset.StandardCharsets; /** @@ -32,7 +34,7 @@ public class RemoteService extends JsonService { @Override public String apply(String request) { byte[] response = client.send(request.getBytes(StandardCharsets.UTF_8)); - return new String(response, StandardCharsets.UTF_8); + return AvaticaUtils.newStringUtf8(response); } } diff --git a/core/src/main/java/org/apache/calcite/avatica/util/AbstractCursor.java b/core/src/main/java/org/apache/calcite/avatica/util/AbstractCursor.java index fed875035..c580246ea 100644 --- a/core/src/main/java/org/apache/calcite/avatica/util/AbstractCursor.java +++ b/core/src/main/java/org/apache/calcite/avatica/util/AbstractCursor.java @@ -26,7 +26,6 @@ import java.lang.reflect.Field; import java.math.BigDecimal; import java.math.RoundingMode; import java.net.URL; -import java.nio.charset.StandardCharsets; import java.sql.Array; import java.sql.Blob; import java.sql.Clob; @@ -852,7 +851,7 @@ public abstract class AbstractCursor implements Cursor { return null; } if (o instanceof byte[]) { - return new String((byte[]) o, StandardCharsets.UTF_8); + return AvaticaUtils.newStringUtf8((byte[]) o); } else if (o instanceof ByteString) { return ((ByteString) o).toString(); } @@ -901,7 +900,7 @@ public abstract class AbstractCursor implements Cursor { return null; } // Need to base64 decode the string. - return new String(bytes, StandardCharsets.UTF_8); + return AvaticaUtils.newStringUtf8(bytes); } } diff --git a/core/src/main/java/org/apache/calcite/avatica/util/Base64.java b/core/src/main/java/org/apache/calcite/avatica/util/Base64.java index 34cece4c2..ee5ba2355 100644 --- a/core/src/main/java/org/apache/calcite/avatica/util/Base64.java +++ b/core/src/main/java/org/apache/calcite/avatica/util/Base64.java @@ -46,7 +46,8 @@ import java.util.Locale; * might make a call like this:</p> * * <code>String encoded = Base64.encodeBytes( mybytes, Base64.GZIP | Base64.DO_BREAK_LINES );</code> - * <p>to compress the data before encoding it and then making the output have newline characters.</p> + * <p>to compress the data before encoding it and + * then making the output have newline characters.</p> * <p>Also...</p> * <code>String encoded = Base64.encodeBytes( crazyString.getBytes() );</code> * @@ -848,7 +849,8 @@ public class Base64 * @throws IllegalArgumentException if source array, offset, or length are invalid * @since 2.0 */ - public static String encodeBytes( byte[] source, int off, int len, int options ) throws java.io.IOException { + public static String encodeBytes( byte[] source, int off, int len, int options ) + throws java.io.IOException { byte[] encoded = encodeBytesToBytes( source, off, len, options ); // Return value according to relevant encoding. @@ -880,7 +882,8 @@ public class Base64 try { encoded = encodeBytesToBytes( source, 0, source.length, Base64.NO_OPTIONS ); } catch( java.io.IOException ex ) { - assert false : "IOExceptions only come from GZipping, which is turned off: " + ex.getMessage(); + assert false : "IOExceptions only come from GZipping, which is turned off: " + + ex.getMessage(); } return encoded; } @@ -904,7 +907,8 @@ public class Base64 * @throws IllegalArgumentException if source array, offset, or length are invalid * @since 2.3.1 */ - public static byte[] encodeBytesToBytes( byte[] source, int off, int len, int options ) throws java.io.IOException { + public static byte[] encodeBytesToBytes( byte[] source, int off, int len, int options ) + throws java.io.IOException { if( source == null ){ throw new NullPointerException( "Cannot serialize a null array." ); @@ -1063,11 +1067,13 @@ public class Base64 } // end if if( srcOffset < 0 || srcOffset + 3 >= source.length ){ throw new IllegalArgumentException( String.format( Locale.ROOT, - "Source array with length %d cannot have offset of %d and still process four bytes.", source.length, srcOffset ) ); + "Source array with length %d cannot have offset of %d and still process four bytes.", + source.length, srcOffset ) ); } // end if if( destOffset < 0 || destOffset +2 >= destination.length ){ throw new IllegalArgumentException( String.format( Locale.ROOT, - "Destination array with length %d cannot have offset of %d and still store three bytes.", destination.length, destOffset ) ); + "Destination array with length %d cannot have offset of %d and still store three bytes.", + destination.length, destOffset ) ); } // end if @@ -1144,7 +1150,8 @@ public class Base64 // try { decoded = decode( source, 0, source.length, Base64.NO_OPTIONS ); // } catch( java.io.IOException ex ) { -// assert false : "IOExceptions only come from GZipping, which is turned off: " + ex.getMessage(); +// assert false : "IOExceptions only come from GZipping, which is turned off: " + +// ex.getMessage(); // } return decoded; } @@ -1177,14 +1184,16 @@ public class Base64 } // end if if( off < 0 || off + len > source.length ){ throw new IllegalArgumentException( String.format( Locale.ROOT, - "Source array with length %d cannot have offset of %d and process %d bytes.", source.length, off, len ) ); + "Source array with length %d cannot have offset of %d and process %d bytes.", + source.length, off, len ) ); } // end if if( len == 0 ){ return new byte[0]; }else if( len < 4 ){ throw new IllegalArgumentException( - "Base64-encoded string must have at least four characters, but length specified was " + len ); + "Base64-encoded string must have at least four characters, but length specified was " + + len ); } // end if byte[] DECODABET = getDecodabet( options ); @@ -1512,7 +1521,8 @@ public class Base64 // Check for size of file if( file.length() > Integer.MAX_VALUE ) { - throw new java.io.IOException( "File is too big for this convenience method (" + file.length() + " bytes)." ); + throw new java.io.IOException( "File is too big for this convenience method (" + + file.length() + " bytes)." ); } // end if: file too big for int index buffer = new byte[ (int)file.length() ]; @@ -1566,7 +1576,8 @@ public class Base64 { // Set up some useful variables java.io.File file = new java.io.File( filename ); - byte[] buffer = new byte[ Math.max((int)(file.length() * 1.4+1),40) ]; // Need max() for math on small files (v2.2.1); Need +1 for a few corner cases (v2.3.5) + byte[] buffer = new byte[ Math.max((int)(file.length() * 1.4+1),40) ]; + // Need max() for math on small files (v2.2.1); Need +1 for a few corner cases (v2.3.5) int length = 0; int numBytes = 0; diff --git a/core/src/main/java/org/apache/calcite/avatica/util/ByteString.java b/core/src/main/java/org/apache/calcite/avatica/util/ByteString.java index 2bd24e04c..86b934a31 100644 --- a/core/src/main/java/org/apache/calcite/avatica/util/ByteString.java +++ b/core/src/main/java/org/apache/calcite/avatica/util/ByteString.java @@ -134,7 +134,7 @@ public class ByteString implements Comparable<ByteString>, Serializable { default: throw new IllegalArgumentException("bad base " + base); } - return new String(chars, 0, j); + return String.valueOf(chars, 0, j); } /** diff --git a/core/src/main/java/org/apache/calcite/avatica/util/Cursor.java b/core/src/main/java/org/apache/calcite/avatica/util/Cursor.java index 7ba605dac..9eeb2df7c 100644 --- a/core/src/main/java/org/apache/calcite/avatica/util/Cursor.java +++ b/core/src/main/java/org/apache/calcite/avatica/util/Cursor.java @@ -78,7 +78,7 @@ public interface Cursor extends AutoCloseable { /** * Accessor of a column value. */ - public interface Accessor { + interface Accessor { boolean wasNull() throws SQLException; String getString() throws SQLException; diff --git a/core/src/main/java/org/apache/calcite/avatica/util/DateTimeUtils.java b/core/src/main/java/org/apache/calcite/avatica/util/DateTimeUtils.java index a4fdb7f0a..b342c94b7 100644 --- a/core/src/main/java/org/apache/calcite/avatica/util/DateTimeUtils.java +++ b/core/src/main/java/org/apache/calcite/avatica/util/DateTimeUtils.java @@ -230,7 +230,7 @@ public class DateTimeUtils { } NumberFormat nf = NumberFormat.getIntegerInstance(Locale.ROOT); Number num = nf.parse(s, pp); - if ((num == null) || (pp.getIndex() != s.length())) { + if (num == null || pp.getIndex() != s.length()) { // Invalid decimal portion return null; } @@ -1119,7 +1119,7 @@ public class DateTimeUtils { public static long floorDiv(long x, long y) { long r = x / y; // if the signs are different and modulo not zero, round down - if ((x ^ y) < 0 && (r * y != x)) { + if ((x ^ y) < 0 && r * y != x) { r--; } return r; diff --git a/core/src/main/java/org/apache/calcite/avatica/util/Spaces.java b/core/src/main/java/org/apache/calcite/avatica/util/Spaces.java index 64694003c..73f70949e 100644 --- a/core/src/main/java/org/apache/calcite/avatica/util/Spaces.java +++ b/core/src/main/java/org/apache/calcite/avatica/util/Spaces.java @@ -171,7 +171,7 @@ public class Spaces { addAll( new AbstractList<String>() { public String get(int index) { - return new String(chars, 0, offset + index); + return String.valueOf(chars, 0, offset + index); } public int size() { diff --git a/core/src/test/java/org/apache/calcite/avatica/remote/AvaticaCommonsHttpClientImplTest.java b/core/src/test/java/org/apache/calcite/avatica/remote/AvaticaCommonsHttpClientImplTest.java index 8b2a34b36..d4dacdf44 100644 --- a/core/src/test/java/org/apache/calcite/avatica/remote/AvaticaCommonsHttpClientImplTest.java +++ b/core/src/test/java/org/apache/calcite/avatica/remote/AvaticaCommonsHttpClientImplTest.java @@ -16,6 +16,8 @@ */ package org.apache.calcite.avatica.remote; +import org.apache.calcite.avatica.AvaticaUtils; + import org.apache.hc.client5.http.classic.methods.HttpPost; import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse; import org.apache.hc.client5.http.protocol.HttpClientContext; @@ -72,7 +74,7 @@ public class AvaticaCommonsHttpClientImplTest { when(goodResponse.getEntity()).thenReturn(responseEntity); byte[] responseBytes = client.send(requestBytes); - assertEquals("success", new String(responseBytes, UTF_8)); + assertEquals("success", AvaticaUtils.newStringUtf8(responseBytes)); } @Test public void testRetryOnMissingHttpResponse() throws Exception { @@ -104,7 +106,7 @@ public class AvaticaCommonsHttpClientImplTest { when(goodResponse.getEntity()).thenReturn(responseEntity); byte[] responseBytes = client.send(requestBytes); - assertEquals("success", new String(responseBytes, UTF_8)); + assertEquals("success", AvaticaUtils.newStringUtf8(responseBytes)); } } diff --git a/core/src/test/java/org/apache/calcite/avatica/remote/TypedValueTest.java b/core/src/test/java/org/apache/calcite/avatica/remote/TypedValueTest.java index 50d492efe..3c0575e10 100644 --- a/core/src/test/java/org/apache/calcite/avatica/remote/TypedValueTest.java +++ b/core/src/test/java/org/apache/calcite/avatica/remote/TypedValueTest.java @@ -16,6 +16,7 @@ */ package org.apache.calcite.avatica.remote; +import org.apache.calcite.avatica.AvaticaUtils; import org.apache.calcite.avatica.ColumnMetaData; import org.apache.calcite.avatica.ColumnMetaData.Rep; import org.apache.calcite.avatica.ColumnMetaData.ScalarType; @@ -180,7 +181,7 @@ public class TypedValueTest { final byte[] b64Bytes = Base64.encodeBytes(bytes).getBytes(UTF_8); TypedValue tv = TypedValue.ofLocal(Rep.BYTE_STRING, new ByteString(bytes)); // JSON encodes it as base64 - assertEquals(new String(b64Bytes, UTF_8), tv.value); + assertEquals(AvaticaUtils.newStringUtf8(b64Bytes), tv.value); // Get the protobuf variant Common.TypedValue protoTv = tv.toProto(); @@ -193,7 +194,7 @@ public class TypedValueTest { assertArrayEquals(bytes, protoByteString.toByteArray()); // We should have the b64 string as a backwards compatibility feature - assertEquals(new String(b64Bytes, UTF_8), + assertEquals(AvaticaUtils.newStringUtf8(b64Bytes), protoTv.getStringValue()); } diff --git a/gradle.properties b/gradle.properties index 706ce898a..88627529b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -50,10 +50,8 @@ org.owasp.dependencycheck.version=5.2.2 # Tools checkerframework.version=3.10.0 -checkstyle.version=6.18 +checkstyle.version=10.3.2 spotbugs.version=3.1.11 -# For Checkstyle -hydromatic-toolbox.version=0.3 asm.version=7.1 bouncycastle.version=1.60 diff --git a/metrics/src/main/java/org/apache/calcite/avatica/metrics/Timer.java b/metrics/src/main/java/org/apache/calcite/avatica/metrics/Timer.java index be792cc70..29d29ad1d 100644 --- a/metrics/src/main/java/org/apache/calcite/avatica/metrics/Timer.java +++ b/metrics/src/main/java/org/apache/calcite/avatica/metrics/Timer.java @@ -26,7 +26,7 @@ public interface Timer extends Metric { /** * A object that tracks an active timing state. */ - public interface Context extends AutoCloseable { + interface Context extends AutoCloseable { /** * Stops the timer. */ diff --git a/server/src/main/java/org/apache/calcite/avatica/server/AvaticaJsonHandler.java b/server/src/main/java/org/apache/calcite/avatica/server/AvaticaJsonHandler.java index 94bee6a6e..709b2d80b 100644 --- a/server/src/main/java/org/apache/calcite/avatica/server/AvaticaJsonHandler.java +++ b/server/src/main/java/org/apache/calcite/avatica/server/AvaticaJsonHandler.java @@ -88,7 +88,7 @@ public class AvaticaJsonHandler extends AbstractAvaticaHandler { public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { - try (final Context ctx = requestTimer.start()) { + try (Context ctx = requestTimer.start()) { if (!isUserPermitted(serverConfig, baseRequest, request, response)) { LOG.debug("HTTP request from {} is unauthenticated and authentication is required", request.getRemoteAddr()); @@ -110,7 +110,7 @@ public class AvaticaJsonHandler extends AbstractAvaticaHandler { if (encoding == null) { encoding = "UTF-8"; } - rawRequest = new String(bytes, encoding); + rawRequest = AvaticaUtils.newString(bytes, encoding); } finally { // Reset the offset into the buffer after we're done buffer.reset(); diff --git a/server/src/main/java/org/apache/calcite/avatica/server/AvaticaProtobufHandler.java b/server/src/main/java/org/apache/calcite/avatica/server/AvaticaProtobufHandler.java index 16e27ffae..9cd02a772 100644 --- a/server/src/main/java/org/apache/calcite/avatica/server/AvaticaProtobufHandler.java +++ b/server/src/main/java/org/apache/calcite/avatica/server/AvaticaProtobufHandler.java @@ -90,7 +90,7 @@ public class AvaticaProtobufHandler extends AbstractAvaticaHandler { public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { - try (final Context ctx = this.requestTimer.start()) { + try (Context ctx = this.requestTimer.start()) { if (!request.getMethod().equals("POST")) { response.setStatus(HttpServletResponse.SC_BAD_REQUEST); response.getOutputStream().write( diff --git a/server/src/test/java/org/apache/calcite/avatica/RemoteDriverTest.java b/server/src/test/java/org/apache/calcite/avatica/RemoteDriverTest.java index 525a1e72b..61c4b3846 100644 --- a/server/src/test/java/org/apache/calcite/avatica/RemoteDriverTest.java +++ b/server/src/test/java/org/apache/calcite/avatica/RemoteDriverTest.java @@ -579,7 +579,7 @@ public class RemoteDriverTest { assertEquals(2, metaData.getColumnCount()); assertEquals("C1", metaData.getColumnName(1)); assertEquals("C2", metaData.getColumnName(2)); - for (int i = 0; i < maxRowCount || (maxRowCount == 0 && i < 3); i++) { + for (int i = 0; i < maxRowCount || maxRowCount == 0 && i < 3; i++) { assertTrue(resultSet.next()); } assertFalse(resultSet.next()); @@ -1334,7 +1334,7 @@ public class RemoteDriverTest { + " (id varchar(1) not null, col1 varchar(1) not null)"; assertFalse(stmt.execute(sql)); } - try (final PreparedStatement pstmt = + try (PreparedStatement pstmt = conn.prepareStatement("INSERT INTO " + tableName + " values(?, ?)")) { pstmt.setString(1, "a"); pstmt.setString(2, "b"); diff --git a/server/src/test/java/org/apache/calcite/avatica/remote/AlternatingRemoteMetaTest.java b/server/src/test/java/org/apache/calcite/avatica/remote/AlternatingRemoteMetaTest.java index 849e6c547..41c84fe3d 100644 --- a/server/src/test/java/org/apache/calcite/avatica/remote/AlternatingRemoteMetaTest.java +++ b/server/src/test/java/org/apache/calcite/avatica/remote/AlternatingRemoteMetaTest.java @@ -321,7 +321,7 @@ public class AlternatingRemoteMetaTest { final Map<String, ConnectionPropertiesImpl> m = ((RemoteMeta) getMeta(conn)).propsMap; assertFalse("remote connection map should start ignorant", m.containsKey(id)); // force creating a connection object on the remote side. - try (final Statement stmt = conn.createStatement()) { + try (Statement stmt = conn.createStatement()) { assertTrue("creating a statement starts a local object.", m.containsKey(id)); assertTrue(stmt.execute("select count(1) from EMP")); } @@ -338,7 +338,7 @@ public class AlternatingRemoteMetaTest { defaultAutoCommit, remoteConn.getAutoCommit()); // further interaction with the connection will force a sync - try (final Statement stmt = conn.createStatement()) { + try (Statement stmt = conn.createStatement()) { assertEquals(!defaultAutoCommit, remoteConn.getAutoCommit()); assertFalse("local values should be clean", m.get(id).isDirty()); } diff --git a/server/src/test/java/org/apache/calcite/avatica/remote/RemoteMetaTest.java b/server/src/test/java/org/apache/calcite/avatica/remote/RemoteMetaTest.java index be657f04f..0d34fb433 100644 --- a/server/src/test/java/org/apache/calcite/avatica/remote/RemoteMetaTest.java +++ b/server/src/test/java/org/apache/calcite/avatica/remote/RemoteMetaTest.java @@ -257,7 +257,7 @@ public class RemoteMetaTest { final Map<String, ConnectionPropertiesImpl> m = ((RemoteMeta) getMeta(conn)).propsMap; assertFalse("remote connection map should start ignorant", m.containsKey(id)); // force creating a connection object on the remote side. - try (final Statement stmt = conn.createStatement()) { + try (Statement stmt = conn.createStatement()) { assertTrue("creating a statement starts a local object.", m.containsKey(id)); assertTrue(stmt.execute("select count(1) from EMP")); } @@ -274,7 +274,7 @@ public class RemoteMetaTest { defaultAutoCommit, remoteConn.getAutoCommit()); // further interaction with the connection will force a sync - try (final Statement stmt = conn.createStatement()) { + try (Statement stmt = conn.createStatement()) { assertEquals(!defaultAutoCommit, remoteConn.getAutoCommit()); assertFalse("local values should be clean", m.get(id).isDirty()); } @@ -391,8 +391,8 @@ public class RemoteMetaTest { @Test public void testExceptionPropagation() throws Exception { final String sql = "SELECT * from EMP LIMIT FOOBARBAZ"; ConnectionSpec.getDatabaseLock().lock(); - try (final AvaticaConnection conn = (AvaticaConnection) DriverManager.getConnection(url); - final Statement stmt = conn.createStatement()) { + try (AvaticaConnection conn = (AvaticaConnection) DriverManager.getConnection(url); + Statement stmt = conn.createStatement()) { try { // invalid SQL stmt.execute(sql); @@ -459,11 +459,11 @@ public class RemoteMetaTest { final String tableName = "testbinaryandstrs"; final byte[] data = "asdf".getBytes(StandardCharsets.UTF_8); ConnectionSpec.getDatabaseLock().lock(); - try (final Connection conn = DriverManager.getConnection(url); - final Statement stmt = conn.createStatement()) { + try (Connection conn = DriverManager.getConnection(url); + Statement stmt = conn.createStatement()) { assertFalse(stmt.execute("DROP TABLE IF EXISTS " + tableName)); assertFalse(stmt.execute("CREATE TABLE " + tableName + "(id int, bin BINARY(4))")); - try (final PreparedStatement prepStmt = conn.prepareStatement( + try (PreparedStatement prepStmt = conn.prepareStatement( "INSERT INTO " + tableName + " values(1, ?)")) { prepStmt.setBytes(1, data); assertFalse(prepStmt.execute()); @@ -475,7 +475,7 @@ public class RemoteMetaTest { assertArrayEquals("Bytes were " + Arrays.toString(results.getBytes(2)), data, results.getBytes(2)); // as should string - assertEquals(new String(data, StandardCharsets.UTF_8), results.getString(2)); + assertEquals(AvaticaUtils.newStringUtf8(data), results.getString(2)); assertFalse(results.next()); } } finally { @@ -552,8 +552,8 @@ public class RemoteMetaTest { final String productTable = "commitrollback_products"; final String salesTable = "commitrollback_sales"; ConnectionSpec.getDatabaseLock().lock(); - try (final Connection conn = DriverManager.getConnection(url); - final Statement stmt = conn.createStatement()) { + try (Connection conn = DriverManager.getConnection(url); + Statement stmt = conn.createStatement()) { assertFalse(stmt.execute("DROP TABLE IF EXISTS " + productTable)); assertFalse( stmt.execute( @@ -652,7 +652,7 @@ public class RemoteMetaTest { @Test public void getAvaticaVersion() throws Exception { ConnectionSpec.getDatabaseLock().lock(); - try (final Connection conn = DriverManager.getConnection(url)) { + try (Connection conn = DriverManager.getConnection(url)) { DatabaseMetaData metadata = conn.getMetaData(); assertTrue("DatabaseMetaData is not an instance of AvaticaDatabaseMetaData", metadata instanceof AvaticaSpecificDatabaseMetaData); @@ -713,7 +713,7 @@ public class RemoteMetaTest { final Properties props = new Properties(); props.setProperty("foo", "bar"); final Properties originalProps = (Properties) props.clone(); - try (final Connection conn = DriverManager.getConnection(url, props)) { + try (Connection conn = DriverManager.getConnection(url, props)) { // The contents of the two properties objects should not have changed after connecting. assertEquals(props, originalProps); } diff --git a/server/src/test/java/org/apache/calcite/avatica/server/AbstractAvaticaHandlerTest.java b/server/src/test/java/org/apache/calcite/avatica/server/AbstractAvaticaHandlerTest.java index f8e79ae98..caf0fb3a0 100644 --- a/server/src/test/java/org/apache/calcite/avatica/server/AbstractAvaticaHandlerTest.java +++ b/server/src/test/java/org/apache/calcite/avatica/server/AbstractAvaticaHandlerTest.java @@ -16,6 +16,7 @@ */ package org.apache.calcite.avatica.server; +import org.apache.calcite.avatica.AvaticaUtils; import org.apache.calcite.avatica.remote.AuthenticationType; import org.eclipse.jetty.server.Request; @@ -25,7 +26,6 @@ import org.junit.Before; import org.junit.Test; import java.net.HttpURLConnection; -import java.nio.charset.StandardCharsets; import javax.servlet.ServletInputStream; import javax.servlet.ServletOutputStream; import javax.servlet.http.HttpServletRequest; @@ -84,7 +84,7 @@ public class AbstractAvaticaHandlerTest { } @Override public boolean matches(Object item) { - String msg = new String((byte[]) item, StandardCharsets.UTF_8); + String msg = AvaticaUtils.newStringUtf8((byte[]) item); return msg.contains("User is not authenticated"); } diff --git a/server/src/test/java/org/apache/calcite/avatica/server/HttpServerSpnegoWithoutJaasTest.java b/server/src/test/java/org/apache/calcite/avatica/server/HttpServerSpnegoWithoutJaasTest.java index 025e2046f..85d9f60c5 100644 --- a/server/src/test/java/org/apache/calcite/avatica/server/HttpServerSpnegoWithoutJaasTest.java +++ b/server/src/test/java/org/apache/calcite/avatica/server/HttpServerSpnegoWithoutJaasTest.java @@ -16,6 +16,7 @@ */ package org.apache.calcite.avatica.server; +import org.apache.calcite.avatica.AvaticaUtils; import org.apache.calcite.avatica.ConnectionConfig; import org.apache.calcite.avatica.ConnectionConfigImpl; import org.apache.calcite.avatica.SpnegoTestUtil; @@ -233,7 +234,7 @@ public class HttpServerSpnegoWithoutJaasTest { // We should get a response which is "OK" with our client's name assertNotNull(response); assertEquals("OK " + SpnegoTestUtil.CLIENT_NAME, - new String(response, StandardCharsets.UTF_8)); + AvaticaUtils.newStringUtf8(response)); } } diff --git a/src/main/config/checkstyle/checker.xml b/src/main/config/checkstyle/checker.xml index 4035432b8..8903218c8 100644 --- a/src/main/config/checkstyle/checker.xml +++ b/src/main/config/checkstyle/checker.xml @@ -31,6 +31,7 @@ <!-- Calcite customization of default Checkstyle behavior --> <module name="Checker"> <property name="localeLanguage" value="en"/> + <property name="cacheFile" value="target/checkstyle-cachefile"/> <!-- Checks for Javadoc comments (checker). --> <!-- See http://checkstyle.sf.net/config_javadoc.html --> @@ -38,7 +39,6 @@ <module name="JavadocPackage"/> <module name="TreeWalker"> - <property name="cacheFile" value="target/checkstyle-cachefile"/> <!-- Checks for blocks. You know, those {}'s --> <!-- See http://checkstyle.sf.net/config_blocks.html --> @@ -191,14 +191,6 @@ <property name="message" value="C-style comment"/> </module> - <!-- Checks for Size Violations. --> - <!-- See http://checkstyle.sf.net/config_sizes.html --> - <!-- Lines cannot exceed 80 chars, except if they are hyperlinks - or strings (possibly preceded by '+' and followed by say '),'. --> - <module name="LineLength"> - <property name="max" value="100"/> - <property name="ignorePattern" value="^import|@see|@link|@BaseMessage|href|^[ +]*".*"[);,]*$"/> - </module> <!-- Over time, we will revise this down --> <module name="MethodLength"> <property name="max" value="390"/> @@ -226,30 +218,35 @@ <!-- No extra whitespace around types --> <module name="GenericWhitespace"/> - <!-- Required for SuppressionCommentFilter below --> - <module name="FileContentsHolder"/> - </module> + <!-- Setup special comments to suppress specific checks from source files --> + <module name="SuppressionCommentFilter"> + <property name="offCommentFormat" value="CHECKSTYLE\: stop ([\w\|]+)"/> + <property name="onCommentFormat" value="CHECKSTYLE\: resume ([\w\|]+)"/> + <property name="checkFormat" value="$1"/> + </module> - <!-- Setup special comments to suppress specific checks from source files --> - <module name="SuppressionCommentFilter"> - <property name="offCommentFormat" value="CHECKSTYLE\: stop ([\w\|]+)"/> - <property name="onCommentFormat" value="CHECKSTYLE\: resume ([\w\|]+)"/> - <property name="checkFormat" value="$1"/> - </module> + <!-- Turn off all checks between OFF and ON --> + <module name="SuppressionCommentFilter"> + <property name="offCommentFormat" value="CHECKSTYLE\: OFF"/> + <property name="onCommentFormat" value="CHECKSTYLE\: ON"/> + </module> - <!-- Turn off all checks between OFF and ON --> - <module name="SuppressionCommentFilter"> - <property name="offCommentFormat" value="CHECKSTYLE\: OFF"/> - <property name="onCommentFormat" value="CHECKSTYLE\: ON"/> - </module> + <!-- Turn off checks for the next N lines. --> + <module name="SuppressWithNearbyCommentFilter"> + <property name="commentFormat" value="CHECKSTYLE: +IGNORE (\d+)"/> + <property name="influenceFormat" value="$1"/> + </module> - <!-- Turn off checks for the next N lines. --> - <module name="SuppressWithNearbyCommentFilter"> - <property name="commentFormat" value="CHECKSTYLE: +IGNORE (\d+)"/> - <property name="influenceFormat" value="$1"/> + <!-- Required for SuppressionCommentFilter below --> + </module> + <!-- Checks for Size Violations. --> + <!-- See http://checkstyle.sf.net/config_sizes.html --> + <!-- Lines cannot exceed 80 chars, except if they are hyperlinks + or strings (possibly preceded by '+' and followed by say '),'. --> + <module name="LineLength"> + <property name="max" value="100"/> + <property name="ignorePattern" value="^import|@see|@link|@BaseMessage|href|^[ +]*".*"[);,]*$"/> </module> - - <module name="net.hydromatic.toolbox.checkstyle.HydromaticFileSetCheck"/> <module name="SuppressionFilter"> <property name="file" value="${checkstyle.suppressions.file}"/>
