Skip to content

Commit 64bb35c

Browse files
authored
Add ErrorProne Plugin for Gradle (#81)
* Specify Locale.ROOT in toUpperCase method * Fix string format usage * Avoid double brace initialization in StorageCredentialCacheTest * Add ErrorProne Plugin for Gradle
1 parent ecea59a commit 64bb35c

File tree

8 files changed

+39
-34
lines changed

8 files changed

+39
-34
lines changed

build.gradle

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ plugins {
2929
id "idea"
3030
id "eclipse"
3131
id "org.jetbrains.gradle.plugin.idea-ext" version "1.1.8"
32+
id "net.ltgt.errorprone" version "4.0.1"
3233
}
3334

3435
allprojects {
@@ -50,10 +51,14 @@ subprojects {
5051
apply plugin: "com.diffplug.spotless"
5152
apply plugin: "jacoco-report-aggregation"
5253
apply plugin: "groovy"
54+
apply plugin: "net.ltgt.errorprone"
5355

5456
tasks.withType(JavaCompile).configureEach {
5557
options.compilerArgs << "-Xlint:unchecked"
5658
options.compilerArgs << "-Xlint:deprecation"
59+
options.errorprone.disableAllWarnings = true
60+
options.errorprone.disableWarningsInGeneratedCode = true
61+
options.errorprone.error("StringCaseLocaleUsage")
5762

5863
// TODO Disabled until the code is only Java 11/17, see #76
5964
// options.release = 17
@@ -76,6 +81,7 @@ subprojects {
7681
testImplementation(libs.assertj.core)
7782
testImplementation(libs.mockito.core)
7883

84+
errorprone("com.google.errorprone:error_prone_core:${libs.errorprone.get().version}")
7985
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
8086
}
8187

gradle/libs.versions.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ commons-codec1 = { module = "commons-codec:commons-codec", version = "1.17.0" }
3333
commons-lang3 = { module = "org.apache.commons:commons-lang3", version = "3.14.0" }
3434
dropwizard-bom = { module = "io.dropwizard:dropwizard-bom", version = "4.0.7" }
3535
eclipselink = { module = "org.eclipse.persistence:eclipselink", version = "4.0.3" }
36+
errorprone = { module = "com.google.errorprone:error_prone_core", version = "2.29.2" }
3637
google-cloud-storage-bom = { module = "com.google.cloud:google-cloud-storage-bom", version = "2.40.1" }
3738
guava = { module = "com.google.guava:guava", version = "33.2.1-jre" }
3839
h2 = { module = "com.h2database:h2", version = "2.2.224" }

polaris-core/src/main/java/io/polaris/core/storage/cache/StorageCredentialCache.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,8 @@ public Map<String, String> getOrGenerateSubScopeCreds(
138138
.addKeyValue("errorMessage", scopedCredentialsResult.getExtraInformation())
139139
.log("Failed to get subscoped credentials");
140140
throw new UnprocessableEntityException(
141-
"Failed to get subscoped credentials: "
142-
+ scopedCredentialsResult.getExtraInformation());
141+
"Failed to get subscoped credentials: %s",
142+
scopedCredentialsResult.getExtraInformation());
143143
};
144144
return cache.get(key, loader).convertToMapOfString();
145145
}

polaris-core/src/test/java/io/polaris/core/storage/cache/StorageCredentialCacheTest.java

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package io.polaris.core.storage.cache;
1717

18+
import com.google.common.collect.ImmutableMap;
1819
import io.polaris.core.PolarisCallContext;
1920
import io.polaris.core.PolarisDefaultDiagServiceImpl;
2021
import io.polaris.core.PolarisDiagnostics;
@@ -382,32 +383,29 @@ private static List<PolarisMetaStoreManager.ScopedCredentialsResult> getFakeScop
382383
: String.valueOf(Long.MAX_VALUE);
383384
res.add(
384385
new PolarisMetaStoreManager.ScopedCredentialsResult(
385-
new EnumMap<>(PolarisCredentialProperty.class) {
386-
{
387-
put(PolarisCredentialProperty.AWS_KEY_ID, "key_id_" + finalI);
388-
put(PolarisCredentialProperty.AWS_SECRET_KEY, "key_secret_" + finalI);
389-
put(PolarisCredentialProperty.EXPIRATION_TIME, expireTime);
390-
}
391-
}));
386+
new EnumMap<>(
387+
ImmutableMap.<PolarisCredentialProperty, String>builder()
388+
.put(PolarisCredentialProperty.AWS_KEY_ID, "key_id_" + finalI)
389+
.put(PolarisCredentialProperty.AWS_SECRET_KEY, "key_secret_" + finalI)
390+
.put(PolarisCredentialProperty.EXPIRATION_TIME, expireTime)
391+
.buildOrThrow())));
392392
if (res.size() == number) return res;
393393
res.add(
394394
new PolarisMetaStoreManager.ScopedCredentialsResult(
395-
new EnumMap<>(PolarisCredentialProperty.class) {
396-
{
397-
put(PolarisCredentialProperty.AZURE_SAS_TOKEN, "sas_token_" + finalI);
398-
put(PolarisCredentialProperty.AZURE_ACCOUNT_HOST, "account_host");
399-
put(PolarisCredentialProperty.EXPIRATION_TIME, expireTime);
400-
}
401-
}));
395+
new EnumMap<>(
396+
ImmutableMap.<PolarisCredentialProperty, String>builder()
397+
.put(PolarisCredentialProperty.AZURE_SAS_TOKEN, "sas_token_" + finalI)
398+
.put(PolarisCredentialProperty.AZURE_ACCOUNT_HOST, "account_host")
399+
.put(PolarisCredentialProperty.EXPIRATION_TIME, expireTime)
400+
.buildOrThrow())));
402401
if (res.size() == number) return res;
403402
res.add(
404403
new PolarisMetaStoreManager.ScopedCredentialsResult(
405-
new EnumMap<>(PolarisCredentialProperty.class) {
406-
{
407-
put(PolarisCredentialProperty.GCS_ACCESS_TOKEN, "gcs_token_" + finalI);
408-
put(PolarisCredentialProperty.GCS_ACCESS_TOKEN_EXPIRES_AT, expireTime);
409-
}
410-
}));
404+
new EnumMap<>(
405+
ImmutableMap.<PolarisCredentialProperty, String>builder()
406+
.put(PolarisCredentialProperty.GCS_ACCESS_TOKEN, "gcs_token_" + finalI)
407+
.put(PolarisCredentialProperty.GCS_ACCESS_TOKEN_EXPIRES_AT, expireTime)
408+
.buildOrThrow())));
411409
}
412410
return res;
413411
}

polaris-service/src/main/java/io/polaris/service/admin/PolarisAdminService.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -584,13 +584,12 @@ public void deleteCatalog(String name) {
584584
if (!dropEntityResult.isSuccess()) {
585585
if (dropEntityResult.failedBecauseNotEmpty()) {
586586
throw new BadRequestException(
587-
String.format("Catalog '%s' cannot be dropped, it is not empty", entity.getName()));
587+
"Catalog '%s' cannot be dropped, it is not empty", entity.getName());
588588
} else {
589589
throw new BadRequestException(
590-
String.format(
591-
"Catalog '%s' cannot be dropped, concurrent modification detected. Please try "
592-
+ "again",
593-
entity.getName()));
590+
"Catalog '%s' cannot be dropped, concurrent modification detected. Please try "
591+
+ "again",
592+
entity.getName());
594593
}
595594
}
596595
}
@@ -701,7 +700,7 @@ private void validateUpdateCatalogDiffOrThrow(
701700
.orElseThrow(
702701
() ->
703702
new CommitFailedException(
704-
"Concurrent modification on Catalog '%s'; retry later"));
703+
"Concurrent modification on Catalog '%s'; retry later", name));
705704
return returnedEntity;
706705
}
707706

@@ -826,7 +825,7 @@ public void deletePrincipal(String name) {
826825
.orElseThrow(
827826
() ->
828827
new CommitFailedException(
829-
"Concurrent modification on Principal '%s'; retry later"));
828+
"Concurrent modification on Principal '%s'; retry later", name));
830829
return returnedEntity;
831830
}
832831

@@ -1004,7 +1003,7 @@ public void deletePrincipalRole(String name) {
10041003
.orElseThrow(
10051004
() ->
10061005
new CommitFailedException(
1007-
"Concurrent modification on PrincipalRole '%s'; retry later"));
1006+
"Concurrent modification on PrincipalRole '%s'; retry later", name));
10081007
return returnedEntity;
10091008
}
10101009

@@ -1142,7 +1141,7 @@ public void deleteCatalogRole(String catalogName, String name) {
11421141
.orElseThrow(
11431142
() ->
11441143
new CommitFailedException(
1145-
"Concurrent modification on CatalogRole '%s'; retry later"));
1144+
"Concurrent modification on CatalogRole '%s'; retry later", name));
11461145
return returnedEntity;
11471146
}
11481147

polaris-service/src/main/java/io/polaris/service/catalog/BasePolarisCatalog.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1570,7 +1570,7 @@ private void renameTableLike(
15701570
if (existingEntitySubType == null) {
15711571
// this code path is unexpected
15721572
throw new AlreadyExistsException(
1573-
"Cannot rename %s to %s. Object %s already exists", from, to);
1573+
"Cannot rename %s to %s. Object already exists", from, to);
15741574
} else if (existingEntitySubType == PolarisEntitySubType.TABLE) {
15751575
throw new AlreadyExistsException(
15761576
"Cannot rename %s to %s. Table already exists", from, to);

polaris-service/src/main/java/io/polaris/service/catalog/IcebergCatalogAdapter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ public Response getConfig(String warehouse, SecurityContext securityContext) {
459459
CallContext.getCurrentContext(), authenticatedPrincipal, warehouse);
460460
ResolverStatus resolverStatus = resolver.resolveAll();
461461
if (!resolverStatus.getStatus().equals(ResolverStatus.StatusEnum.SUCCESS)) {
462-
throw new NotFoundException("Unable to find warehouse " + warehouse);
462+
throw new NotFoundException("Unable to find warehouse %s", warehouse);
463463
}
464464
EntityCacheEntry resolvedReferenceCatalog = resolver.getResolvedReferenceCatalog();
465465
Map<String, String> properties =

polaris-service/src/main/java/io/polaris/service/types/NotificationType.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package io.polaris.service.types;
1717

1818
import java.util.Arrays;
19+
import java.util.Locale;
1920
import java.util.Map;
2021
import java.util.Optional;
2122
import java.util.stream.Collectors;
@@ -80,7 +81,7 @@ public static Optional<NotificationType> lookupByName(String name) {
8081
}
8182

8283
for (NotificationType NotificationType : NotificationType.values()) {
83-
if (name.toUpperCase().equals(NotificationType.name())) {
84+
if (name.toUpperCase(Locale.ROOT).equals(NotificationType.name())) {
8485
return Optional.of(NotificationType);
8586
}
8687
}

0 commit comments

Comments
 (0)