Skip to content

Commit 5a4669a

Browse files
committed
add NullAway and fix issues
1 parent ee9f1ec commit 5a4669a

21 files changed

+137
-53
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ make test
5050
1. Open the `Services` tool on the left side of the IDE
5151
2. Click on "+" and select "Quarkus"
5252

53-
Afterwards, the project can be started in IntelliJ by navigating to `Run` -> `Run '...'`.
53+
Afterward, the project can be started in IntelliJ by navigating to `Run` -> `Run '...'`.
5454

5555
## Packaging and running the application
5656

build.gradle.kts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import net.ltgt.gradle.errorprone.CheckSeverity
2+
import net.ltgt.gradle.errorprone.errorprone
13
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
24
import org.gradle.api.tasks.testing.logging.TestLogEvent
35

@@ -6,11 +8,12 @@ plugins {
68
java
79
checkstyle
810
id("io.quarkus")
11+
alias(libs.plugins.errorPronePlugin)
912
alias(libs.plugins.jooqPlugin)
1013
}
1114

1215
description = "AboutBits PostgreSQL Operator"
13-
group = "com.aboutbits.postgresql"
16+
group = "it.aboutbits.postgresql"
1417
version = "0.0.1-SNAPSHOT"
1518

1619
val quarkusPlatformGroupId: String by project
@@ -91,6 +94,12 @@ dependencies {
9194
testImplementation("org.awaitility:awaitility")
9295
testImplementation(libs.assertj)
9396
testImplementation(libs.datafaker)
97+
98+
/**
99+
* NullAway
100+
*/
101+
errorprone(libs.errorProne)
102+
errorprone(libs.nullAway)
94103
}
95104

96105
sourceSets {
@@ -114,6 +123,11 @@ java {
114123
tasks.withType<JavaCompile> {
115124
options.encoding = "UTF-8"
116125
options.compilerArgs.add("-parameters")
126+
127+
options.errorprone {
128+
check("NullAway", CheckSeverity.ERROR)
129+
option("NullAway:AnnotatedPackages", "it.aboutbits.postgresql")
130+
}
117131
}
118132

119133
tasks.quarkusDev {

gradle/libs.versions.toml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,15 @@ scram-client = "3.2"
1414
assertj = "3.27.6"
1515
checkstyle = "12.2.0"
1616
datafaker = "2.5.3"
17+
errorProne = "2.45.0"
18+
errorPronePlugin = "4.2.0"
19+
nullAway = "0.12.15"
1720

1821
[plugins]
22+
# https://github.com/tbroyer/gradle-errorprone-plugin
23+
# https://mvnrepository.com/artifact/net.ltgt.errorprone/net.ltgt.errorprone.gradle.plugin
24+
errorPronePlugin = { id = "net.ltgt.errorprone", version.ref = "errorPronePlugin" }
25+
1926
# https://www.jooq.org/doc/latest/manual/code-generation/codegen-execution/codegen-gradle/
2027
# https://github.com/jOOQ/jOOQ/tree/main/jOOQ-codegen-gradle
2128
# https://mvnrepository.com/artifact/org.jooq.jooq-codegen-gradle/org.jooq.jooq-codegen-gradle.gradle.plugin
@@ -82,3 +89,12 @@ checkstyle = { group = "com.puppycrawl.tools", name = "checkstyle", version.ref
8289
# https://github.com/datafaker-net/datafaker
8390
# https://mvnrepository.com/artifact/net.datafaker/datafaker
8491
datafaker = { group = "net.datafaker", name = "datafaker", version.ref = "datafaker" }
92+
93+
# https://errorprone.info/
94+
# https://github.com/google/error-prone
95+
# https://mvnrepository.com/artifact/com.google.errorprone/error_prone_core
96+
errorProne = { group = "com.google.errorprone", name = "error_prone_core", version.ref = "errorProne" }
97+
98+
# https://github.com/uber/NullAway
99+
# https://mvnrepository.com/artifact/com.uber.nullaway/nullaway
100+
nullAway = { group = "com.uber.nullaway", name = "nullaway", version.ref = "nullAway" }

lombok.config

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@ config.stopBubbling = true
44
lombok.copyableAnnotations += org.jspecify.annotations.Nullable
55
lombok.copyableAnnotations += org.jspecify.annotations.NonNull
66
lombok.addNullAnnotations = jspecify
7+
8+
# Required for NullAway
9+
lombok.addLombokGeneratedAnnotation = true

src/main/java/it/aboutbits/postgresql/core/BaseReconciler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import io.javaoperatorsdk.operator.api.reconciler.UpdateControl;
66
import it.aboutbits.postgresql.crd.connection.ClusterConnection;
77
import lombok.extern.slf4j.Slf4j;
8-
import org.jspecify.annotations.NonNull;
98
import org.jspecify.annotations.NullMarked;
109
import org.jspecify.annotations.Nullable;
1110

@@ -18,12 +17,12 @@
1817
@NullMarked
1918
@Slf4j
2019
public abstract class BaseReconciler<CR extends CustomResource<?, S> & Named, S extends CRStatus> {
21-
@NonNull
2220
protected abstract S newStatus();
2321

2422
public S initializeStatus(CR resource) {
2523
S status = resource.getStatus();
2624

25+
//noinspection ConstantConditions
2726
if (status == null) {
2827
status = newStatus();
2928

@@ -62,6 +61,7 @@ public Optional<ClusterConnection> getReferencedClusterConnection(
6261
.withName(connectionName)
6362
.get();
6463

64+
//noinspection ConstantConditions
6565
if (clusterConnection == null) {
6666
log.error(
6767
"The specified ClusterConnection does not exist [clusterConnection={}/{}]",

src/main/java/it/aboutbits/postgresql/core/KubernetesUtil.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import it.aboutbits.postgresql.crd.connection.ClusterConnection;
55
import org.jspecify.annotations.NullMarked;
66

7+
import java.nio.charset.Charset;
78
import java.util.Base64;
89

910
@NullMarked
@@ -67,7 +68,8 @@ public static Credentials getSecretRefCredentials(
6768
var username = usernameBase64 == null
6869
? null
6970
: new String(
70-
Base64.getDecoder().decode(usernameBase64)
71+
Base64.getDecoder().decode(usernameBase64),
72+
Charset.defaultCharset()
7173
);
7274

7375
var passwordBase64 = data.get(SECRET_DATA_BASIC_AUTH_PASSWORD_KEY);
@@ -78,7 +80,8 @@ public static Credentials getSecretRefCredentials(
7880
));
7981
}
8082
var password = new String(
81-
Base64.getDecoder().decode(passwordBase64)
83+
Base64.getDecoder().decode(passwordBase64),
84+
Charset.defaultCharset()
8285
);
8386

8487
return new Credentials(

src/main/java/it/aboutbits/postgresql/core/PostgreSQLAuthenticationUtil.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.ongres.scram.common.StringPreparation;
44
import it.aboutbits.postgresql.crd.role.RoleSpec;
5+
import lombok.extern.slf4j.Slf4j;
56
import org.jooq.DSLContext;
67
import org.jspecify.annotations.NullMarked;
78

@@ -20,6 +21,7 @@
2021
import static it.aboutbits.postgresql.core.infrastructure.persistence.Tables.PG_AUTHID;
2122

2223
@NullMarked
24+
@Slf4j
2325
public final class PostgreSQLAuthenticationUtil {
2426
private static final String MD5 = "MD5";
2527
private static final String SHA_256 = "SHA-256";
@@ -89,7 +91,8 @@ private static boolean verifyPostgresScramSha256(String postgresVerifier, String
8991
int iterations;
9092
try {
9193
iterations = Integer.parseInt(iterationsAndSalt.substring(0, colonIterationsAndSalt));
92-
} catch (NumberFormatException ex) {
94+
} catch (NumberFormatException e) {
95+
log.error("Invalid iterations format in PostgreSQL verifier: %s".formatted(postgresVerifier), e);
9396
return false;
9497
}
9598
if (iterations <= 0) {
@@ -110,7 +113,8 @@ private static boolean verifyPostgresScramSha256(String postgresVerifier, String
110113
try {
111114
salt = Base64.getDecoder().decode(saltB64);
112115
currentStoredKey = Base64.getDecoder().decode(storedKeyB64);
113-
} catch (IllegalArgumentException ex) {
116+
} catch (IllegalArgumentException e) {
117+
log.error("Invalid salt or stored key format in PostgreSQL verifier: %s".formatted(postgresVerifier), e);
114118
return false;
115119
}
116120

@@ -119,7 +123,7 @@ private static boolean verifyPostgresScramSha256(String postgresVerifier, String
119123
byte[] expectedStoredKey = null;
120124
try {
121125
// RFC 5802/7677:
122-
// saltedPassword := Hi(password, salt, iterations) (PBKDF2-HMAC-SHA-256, 32 bytes)
126+
// saltedPassword := Hi(password, salt, iterations) (PBKDF2-HMAC-SHA-256, 32 bytes)
123127
// clientKey := HMAC(saltedPassword, "Client Key")
124128
// storedKey := H(clientKey) (SHA-256)
125129
saltedPassword = pbkdf2HmacSha256(preparedPassword, salt, iterations, 32);
@@ -160,7 +164,8 @@ private static boolean verifyPostgresMd5(
160164
3,
161165
postgresMd5.length()
162166
);
163-
} catch (IllegalArgumentException ex) {
167+
} catch (IllegalArgumentException e) {
168+
log.error("Invalid MD5 format in PostgreSQL verifier: %s".formatted(postgresMd5), e);
164169
return false; // not valid hex
165170
}
166171

src/main/java/it/aboutbits/postgresql/core/SecretRef.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
@Setter
1212
public class SecretRef {
1313
@Required
14-
private String name;
14+
private String name = "";
1515

1616
/**
1717
* The namespace where the Secret is located.

src/main/java/it/aboutbits/postgresql/crd/connection/ClusterConnectionReconciler.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99
import it.aboutbits.postgresql.core.PostgreSQLContextFactory;
1010
import lombok.RequiredArgsConstructor;
1111
import lombok.extern.slf4j.Slf4j;
12-
import org.jspecify.annotations.NonNull;
12+
import org.jspecify.annotations.NullMarked;
1313

14+
@NullMarked
1415
@Slf4j
1516
@RequiredArgsConstructor
1617
public class ClusterConnectionReconciler
@@ -43,7 +44,7 @@ public UpdateControl<ClusterConnection> reconcile(
4344
}
4445

4546
@Override
46-
protected @NonNull CRStatus newStatus() {
47+
protected CRStatus newStatus() {
4748
return new CRStatus();
4849
}
4950
}

src/main/java/it/aboutbits/postgresql/crd/role/RoleFlags.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
import lombok.Getter;
44
import lombok.RequiredArgsConstructor;
55
import lombok.experimental.Accessors;
6+
import org.jspecify.annotations.NullMarked;
67

8+
@NullMarked
79
@Getter
810
@Accessors(fluent = true)
911
@RequiredArgsConstructor

0 commit comments

Comments
 (0)