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

Enforce modernizer #127

Merged
merged 1 commit into from
Dec 31, 2023
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
5 changes: 2 additions & 3 deletions baseapp/src/main/java/io/trino/gateway/baseapp/BaseApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

import com.codahale.metrics.health.HealthCheck;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.Module;
Expand Down Expand Up @@ -64,7 +63,7 @@ public abstract class BaseApp<T extends AppConfiguration>
private static final Logger logger = LoggerFactory.getLogger(BaseApp.class);

private final Reflections reflections;
private final List<Module> appModules = Lists.newArrayList();
private final ImmutableList.Builder<Module> appModules = ImmutableList.builder();
private Injector injector;

protected BaseApp(String... basePackages)
Expand Down Expand Up @@ -140,7 +139,7 @@ private Injector configureGuice(T configuration, Environment environment)
{
appModules.add(new MetricRegistryModule(environment.metrics()));
appModules.addAll(addModules(configuration, environment));
Injector injector = Guice.createInjector(ImmutableList.copyOf(appModules));
Injector injector = Guice.createInjector(appModules.build());
injector.injectMembers(this);
registerWithInjector(configuration, environment, injector);
return injector;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public Response getBackend(@PathParam("name") String name)
try {
ProxyBackendConfiguration backend = gatewayBackendManager
.getBackendByName(name)
.get();
.orElseThrow();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure about this change.. kinda weird and implied but fine by me anyway.

return Response.ok(backend).build();
}
catch (NoSuchElementException e) {
Expand All @@ -65,7 +65,7 @@ public Response getBackendState(@PathParam("name") String name)
BackendStateManager.BackendState state = gatewayBackendManager
.getBackendByName(name)
.map(backendStateManager::getBackendState)
.get();
.orElseThrow();
return Response.ok(state.getState()).build();
}
catch (NoSuchElementException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public List<QueryDetail> fetchQueryHistory(Optional<String> user)
connectionManager.open();
String sql = "select * from query_history";
if (user.isPresent()) {
sql += " where user_name = '" + user.get() + "'";
sql += " where user_name = '" + user.orElseThrow() + "'";
}
return QueryHistory.upcast(QueryHistory.findBySQL(String.join(" ",
sql,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;

import static java.nio.charset.StandardCharsets.UTF_8;

public class RuleReloadingRoutingGroupSelector
implements RoutingGroupSelector
{
Expand All @@ -47,7 +49,7 @@ public class RuleReloadingRoutingGroupSelector
this.rulesConfigPath = rulesConfigPath;
try {
rules = ruleFactory.createRules(
new FileReader(rulesConfigPath));
new FileReader(rulesConfigPath, UTF_8));
BasicFileAttributes attr = Files.readAttributes(Path.of(rulesConfigPath),
BasicFileAttributes.class);
lastUpdatedTime = attr.lastModifiedTime().toMillis();
Expand Down Expand Up @@ -75,7 +77,7 @@ public String findRoutingGroup(HttpServletRequest request)
log.info(String.format("Updating rules to file modified at %s",
attr.lastModifiedTime()));
rules = ruleFactory.createRules(
new FileReader(rulesConfigPath));
new FileReader(rulesConfigPath, UTF_8));
lastUpdatedTime = attr.lastModifiedTime().toMillis();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import java.security.spec.PKCS8EncodedKeySpec;
import java.security.spec.X509EncodedKeySpec;

import static java.nio.charset.StandardCharsets.UTF_8;

public class LbKeyProvider
{
private final PrivateKey privateKey;
Expand All @@ -47,7 +49,7 @@ public LbKeyProvider(SelfSignKeyPairConfiguration keypairConfig)

try {
String publicKeyRsa = keypairConfig.getPublicKeyRsa();
try (FileReader keyReader = new FileReader(publicKeyRsa);
try (FileReader keyReader = new FileReader(publicKeyRsa, UTF_8);
PemReader pemReader = new PemReader(keyReader)) {
PemObject pemObject = pemReader.readPemObject();
byte[] content = pemObject.getContent();
Expand All @@ -56,7 +58,7 @@ public LbKeyProvider(SelfSignKeyPairConfiguration keypairConfig)
}

String privateKeyRsa = keypairConfig.getPrivateKeyRsa();
try (FileReader keyReader = new FileReader(privateKeyRsa);
try (FileReader keyReader = new FileReader(privateKeyRsa, UTF_8);
PemReader pemReader = new PemReader(keyReader)) {
PemObject pemObject = pemReader.readPemObject();
byte[] content = pemObject.getContent();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import java.util.Random;
import java.util.Scanner;

import static java.nio.charset.StandardCharsets.UTF_8;
import static org.junit.jupiter.api.Assertions.assertTrue;

@TestInstance(Lifecycle.PER_CLASS)
Expand Down Expand Up @@ -89,7 +90,7 @@ public static TestConfig buildGatewayConfigAndSeedDb(int routerPort, String conf

File target = File.createTempFile("config-" + System.currentTimeMillis(), "config.yaml");

FileWriter fw = new FileWriter(target);
FileWriter fw = new FileWriter(target, UTF_8);
fw.append(configStr);
fw.flush();
log.info("Test Gateway Config \n[{}]", configStr);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.util.stream.Stream;

import static io.trino.gateway.ha.router.RoutingGroupSelector.ROUTING_GROUP_HEADER;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.mockito.Mockito.mock;
Expand Down Expand Up @@ -113,7 +114,7 @@ public void testByRoutingRulesEngineFileChange()
{
File file = File.createTempFile("routing_rules", ".yml");

FileWriter fw = new FileWriter(file);
FileWriter fw = new FileWriter(file, UTF_8);
fw.write(
"---\n"
+ "name: \"airflow1\"\n"
Expand All @@ -137,7 +138,7 @@ public void testByRoutingRulesEngineFileChange()
// half of this test runs in <1ms, the gateway may not recognize that the file
// has changed.

fw = new FileWriter(file);
fw = new FileWriter(file, UTF_8);
fw.write(
"---\n"
+ "name: \"airflow2\"\n"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public void testAuthenticatorGetsPrincipal()
LbAuthenticator lbAuth = new LbAuthenticator(authentication, authorization);

assertTrue(lbAuth.authenticate(ID_TOKEN).isPresent());
assertEquals(principal, lbAuth.authenticate(ID_TOKEN).get());
assertEquals(principal, lbAuth.authenticate(ID_TOKEN).orElseThrow());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public void testSuccessfulCookieAuthentication()
{
AuthorizationConfiguration configuration = new AuthorizationConfiguration();
configuration.setAdmin("NO_MEMBER");
configuration.setUser(MEMBER_OF.get());
configuration.setUser(MEMBER_OF.orElseThrow());

Mockito
.when(requestContext.getCookies())
Expand Down Expand Up @@ -120,8 +120,8 @@ public void testSuccessfulHeaderAuthentication()
throws Exception
{
AuthorizationConfiguration configuration = new AuthorizationConfiguration();
configuration.setAdmin(MEMBER_OF.get());
configuration.setUser(MEMBER_OF.get());
configuration.setAdmin(MEMBER_OF.orElseThrow());
configuration.setUser(MEMBER_OF.orElseThrow());

MultivaluedHashMap<String, String> headers = new MultivaluedHashMap<>();
headers.addFirst(HttpHeaders.AUTHORIZATION, String.format("Bearer %s", ID_TOKEN));
Expand Down
1 change: 0 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
<air.check.skip-enforcer>true</air.check.skip-enforcer>
<air.check.skip-dependency>true</air.check.skip-dependency>
<air.check.skip-duplicate-finder>true</air.check.skip-duplicate-finder>
<air.check.skip-modernizer>true</air.check.skip-modernizer>
<air.check.fail-spotbugs>false</air.check.fail-spotbugs>
<air.check.skip-pmd>true</air.check.skip-pmd>

Expand Down