Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update errorprone rules and fix some warning #499

Merged
merged 6 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
import static io.trino.gateway.ha.handler.QueryIdCachingProxyHandler.TRINO_UI_PATH;
import static io.trino.gateway.ha.handler.QueryIdCachingProxyHandler.USER_HEADER;
import static io.trino.gateway.ha.handler.QueryIdCachingProxyHandler.V1_QUERY_PATH;
import static java.nio.charset.StandardCharsets.UTF_8;
import static java.util.Locale.ENGLISH;

public final class ProxyUtils
{
Expand Down Expand Up @@ -80,7 +82,7 @@ public static String getQueryUser(String userHeader, String authorization)
return user;
}

String info = new String(Base64.getDecoder().decode(headerInfo));
String info = new String(Base64.getDecoder().decode(headerInfo), UTF_8);
List<String> parts = Splitter.on(':').limit(2).splitToList(info);
if (parts.size() < 1) {
log.error("No user inside the basic auth text");
Expand All @@ -94,9 +96,9 @@ public static String extractQueryIdIfPresent(HttpServletRequest request, List<St
String path = request.getRequestURI();
String queryParams = request.getQueryString();
try {
String queryText = CharStreams.toString(new InputStreamReader(request.getInputStream()));
String queryText = CharStreams.toString(new InputStreamReader(request.getInputStream(), UTF_8));
if (!isNullOrEmpty(queryText)
&& queryText.toLowerCase().contains("system.runtime.kill_query")) {
&& queryText.toLowerCase(ENGLISH).contains("system.runtime.kill_query")) {
// extract and return the queryId
String[] parts = queryText.split(",");
for (String part : parts) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import java.util.concurrent.TimeUnit;

import static com.nimbusds.openid.connect.sdk.UserInfoResponse.parse;
import static java.util.Locale.ENGLISH;
import static java.util.Objects.requireNonNull;

public class TrinoRequestUser
Expand Down Expand Up @@ -161,7 +162,7 @@ private Optional<String> extractUserFromAuthorizationHeader(String header, Strin
}
}

if (header.toLowerCase().contains("bearer")) {
if (header.toLowerCase(ENGLISH).contains("bearer")) {
return extractUserFromBearerAuth(header, userField);
}
return Optional.empty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public LbFilter(IdTokenAuthenticator idTokenAuthenticator, Authorizer lbAuthoriz
* Filters requests by checking for the token cookie and authorization header,
* and authenticates the user using the filter's authenticator.
*/
@Override
public void filter(final ContainerRequestContext requestContext)
throws WebApplicationException
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import java.util.stream.Stream;

import static com.google.common.collect.ImmutableMap.toImmutableMap;
import static java.util.Locale.ENGLISH;

public class LbFormAuthManager
{
Expand All @@ -52,7 +53,7 @@ public LbFormAuthManager(FormAuthConfiguration configuration,
this.presetUsers = presetUsers;
this.pagePermissions = pagePermissions.entrySet().stream()
.filter(entry -> entry.getValue() != null)
.collect(toImmutableMap(entry -> entry.getKey().toUpperCase(), Map.Entry::getValue));
.collect(toImmutableMap(entry -> entry.getKey().toUpperCase(ENGLISH), Map.Entry::getValue));

if (configuration != null) {
this.lbKeyProvider = new LbKeyProvider(configuration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
import static jakarta.ws.rs.core.Response.Status.FOUND;
import static jakarta.ws.rs.core.Response.Status.UNAUTHORIZED;
import static java.nio.charset.StandardCharsets.UTF_8;
import static java.util.Locale.ENGLISH;

public class LbOAuthManager
{
Expand All @@ -70,7 +71,7 @@ public LbOAuthManager(OAuthConfiguration configuration, Map<String, String> page
this.oauthConfig = configuration;
this.pagePermissions = pagePermissions.entrySet().stream()
.filter(entry -> entry.getValue() != null)
.collect(toImmutableMap(entry -> entry.getKey().toUpperCase(), Map.Entry::getValue));
.collect(toImmutableMap(entry -> entry.getKey().toUpperCase(ENGLISH), Map.Entry::getValue));
}

public String getUserIdField()
Expand All @@ -97,7 +98,8 @@ public Response exchangeCodeForToken(String code, String nonce, String redirectL
TokenRequest tokenRequest = new TokenRequest(
oauthConfig.getTokenEndpoint(),
new ClientSecretBasic(new ClientID(oauthConfig.getClientId()), new Secret(oauthConfig.getClientSecret())),
new AuthorizationCodeGrant(new AuthorizationCode(code), oauthConfig.getRedirectUrl()));
new AuthorizationCodeGrant(new AuthorizationCode(code), oauthConfig.getRedirectUrl()),
null);

TokenResponse tokenResponse;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public static String getResourceFileContent(String fileName)
StringBuilder sb = new StringBuilder();
InputStream inputStream =
HaGatewayTestUtils.class.getClassLoader().getResourceAsStream(fileName);
Scanner scn = new Scanner(inputStream);
Scanner scn = new Scanner(inputStream, UTF_8);
while (scn.hasNextLine()) {
sb.append(scn.nextLine()).append("\n");
}
Expand All @@ -140,7 +140,6 @@ public static void setUpBackend(
{
RequestBody requestBody =
RequestBody.create(
MediaType.parse("application/json; charset=utf-8"),
"{ \"name\": \""
+ name
+ "\",\"proxyTo\": \""
Expand All @@ -151,7 +150,8 @@ public static void setUpBackend(
+ active
+ ",\"routingGroup\": \""
+ routingGroup
+ "\"}");
+ "\"}",
MediaType.parse("application/json; charset=utf-8"));
ebyhr marked this conversation as resolved.
Show resolved Hide resolved
Request request =
new Request.Builder()
.url("http://localhost:" + routerPort + "/entity?entityType=GATEWAY_BACKEND")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ void testRequestDelivery()
throws Exception
{
RequestBody requestBody =
RequestBody.create(MediaType.parse("application/json; charset=utf-8"), "SELECT * from system.runtime.nodes");
RequestBody.create("SELECT * from system.runtime.nodes", MediaType.parse("application/json; charset=utf-8"));
ebyhr marked this conversation as resolved.
Show resolved Hide resolved
Request request =
new Request.Builder()
.url("http://localhost:" + routerPort + "/v1/statement")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ void testRequestDelivery()
throws Exception
{
RequestBody requestBody =
RequestBody.create(MediaType.parse("application/json; charset=utf-8"), "SELECT 1");
RequestBody.create("SELECT 1", MediaType.parse("application/json; charset=utf-8"));
Request request =
new Request.Builder()
.url("http://localhost:" + routerPort + "/v1/statement")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ void testDeleteResourceGroupOk()
throws Exception
{
RequestBody requestBody =
RequestBody.create(MediaType.parse("application/json; charset=utf-8"), "");
RequestBody.create("", MediaType.parse("application/json; charset=utf-8"));
Request request =
new Request.Builder()
.url("http://localhost:" + routerPort + "/trino/resourcegroup/delete/3")
Expand All @@ -230,7 +230,7 @@ void testDeleteResourceGroupNoId()
throws Exception
{
RequestBody requestBody =
RequestBody.create(MediaType.parse("application/json; charset=utf-8"), "");
RequestBody.create("", MediaType.parse("application/json; charset=utf-8"));
Request request =
new Request.Builder()
.url("http://localhost:" + routerPort + "/trino/resourcegroup/delete/")
Expand All @@ -246,7 +246,7 @@ void testDeleteGlobalPropertyOk()
throws Exception
{
RequestBody requestBody =
RequestBody.create(MediaType.parse("application/json; charset=utf-8"), "");
RequestBody.create("", MediaType.parse("application/json; charset=utf-8"));
Request request =
new Request.Builder()
.url("http://localhost:" + routerPort + "/trino/globalproperty/delete/cpu_quota_period")
Expand All @@ -262,7 +262,7 @@ void testDeleteGlobalPropertyNoName()
throws Exception
{
RequestBody requestBody =
RequestBody.create(MediaType.parse("application/json; charset=utf-8"), "");
RequestBody.create("", MediaType.parse("application/json; charset=utf-8"));
Request request =
new Request.Builder()
.url("http://localhost:" + routerPort + "/trino/globalproperty/delete/")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ private List<String> getRoles(String credentials)
private Response makeRequest(Optional<String> credentials)
throws IOException
{
RequestBody emptyRequestBody = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), "");
RequestBody emptyRequestBody = RequestBody.create("", MediaType.parse("application/json; charset=utf-8"));
Request.Builder builder = new Request.Builder()
.url("http://localhost:" + routerPort + "/userinfo")
.post(emptyRequestBody);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ void testSuccessfulCookieAuthentication()
.when(requestContext.getCookies())
.thenReturn(
Map.of(SessionCookie.OAUTH_ID_TOKEN,
new Cookie(SessionCookie.OAUTH_ID_TOKEN, ID_TOKEN)));
new Cookie.Builder(SessionCookie.OAUTH_ID_TOKEN).value(ID_TOKEN).build()));
Mockito
.when(requestContext.getHeaders())
.thenReturn(new MultivaluedHashMap());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ final class TestLbLdapClient
public void initMocks()
{
log.info("initializing test");
org.mockito.MockitoAnnotations.initMocks(this);
org.mockito.MockitoAnnotations.openMocks(this);
}

@AfterEach
Expand Down Expand Up @@ -145,7 +145,7 @@ void testMemberof()
assertThat(lbLdapClient.getMemberOf(user)).isNotEqualTo("Admin,User");
}

class DummyPasswordWarning
static class DummyPasswordWarning
implements org.apache.directory.ldap.client.template.PasswordWarning
{
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ public X509Certificate[] getAcceptedIssuers()
clientBuilder.hostnameVerifier((hostname, session) -> true);
}

public class BadCookieJar
public static class BadCookieJar
implements CookieJar
{
private JavaNetCookieJar cookieJar;
Expand Down
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@
<compilerArgs>
<arg>-XDcompilePolicy=simple</arg>
<arg>-Xplugin:ErrorProne \
-Xep:ClassCanBeStatic:ERROR \
-Xep:DefaultCharset:ERROR \
-Xep:EqualsGetClass:OFF \
-Xep:MissingOverride:ERROR \
-Xep:StringCaseLocaleUsage:ERROR \
-Xep:UnnecessaryParentheses:ERROR \
-Xep:UnusedMethod:ERROR \
-Xep:UnusedVariable:ERROR</arg>
Expand Down