summaryrefslogtreecommitdiff
path: root/core/src/main/java/eu
diff options
context:
space:
mode:
authorMatthias Andreas Benkard <code@mail.matthias.benkard.de>2024-07-18 19:34:08 +0200
committerMatthias Andreas Benkard <code@mail.matthias.benkard.de>2024-07-18 19:34:08 +0200
commitd72462e21a231f864c8695579e6d75c39654e01c (patch)
tree5fc6029b5e3b818e41d1f9b1412b0c6486e4dfd2 /core/src/main/java/eu
parent5aeebfaeb3be84bfb6cd1a103c41da476e5a000b (diff)
feat: JSpecify 1.0.0.
Change-Id: I84cc903128d013ff7f6b6cee29353abbe0a84fc8
Diffstat (limited to 'core/src/main/java/eu')
-rw-r--r--core/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/Formatter.java32
-rw-r--r--core/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/InsertId.java11
-rw-r--r--core/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/KeyValueParameter.java3
-rw-r--r--core/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/Label.java3
-rw-r--r--core/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/LabelProvider.java5
-rw-r--r--core/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/LogEntry.java20
-rw-r--r--core/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/ProviderContext.java5
-rw-r--r--core/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/StructuredParameterProvider.java6
-rw-r--r--core/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/package-info.java3
9 files changed, 48 insertions, 40 deletions
diff --git a/core/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/Formatter.java b/core/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/Formatter.java
index 0b2003d..9c66f82 100644
--- a/core/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/Formatter.java
+++ b/core/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/Formatter.java
@@ -6,17 +6,13 @@ package eu.mulk.quarkus.googlecloud.jsonlogging;
import java.io.PrintWriter;
import java.io.StringWriter;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.ServiceLoader;
+import java.util.*;
import java.util.ServiceLoader.Provider;
import java.util.logging.Level;
import java.util.stream.Collectors;
import org.jboss.logmanager.ExtFormatter;
import org.jboss.logmanager.ExtLogRecord;
+import org.jspecify.annotations.Nullable;
/**
* Formats log records as JSON for consumption by Google Cloud Logging.
@@ -42,7 +38,7 @@ public class Formatter extends ExtFormatter {
private final List<StructuredParameterProvider> parameterProviders;
private final List<LabelProvider> labelProviders;
- private final ThreadLocal<StringBuilder> stringBuilder;
+ private final ThreadLocal<@Nullable StringBuilder> stringBuilder;
/**
* Constructs a {@link Formatter} with custom configuration.
@@ -125,8 +121,9 @@ public class Formatter extends ExtFormatter {
String insertId = null;
- if (logRecord.getParameters() != null) {
- for (var parameter : logRecord.getParameters()) {
+ var logRecordParameters = logRecord.getParameters();
+ if (logRecordParameters != null) {
+ for (var parameter : logRecordParameters) {
if (parameter instanceof StructuredParameter) {
parameters.add((StructuredParameter) parameter);
} else if (parameter instanceof Label) {
@@ -158,7 +155,7 @@ public class Formatter extends ExtFormatter {
logRecord.getLevel().intValue() >= 1000 ? ERROR_EVENT_TYPE : null,
insertId);
- var b = stringBuilder.get();
+ var b = Objects.requireNonNull(stringBuilder.get());
b.delete(0, b.length());
b.append("{");
entry.json(b);
@@ -166,7 +163,7 @@ public class Formatter extends ExtFormatter {
return b.toString();
}
- private static LogEntry.SourceLocation sourceLocationOf(ExtLogRecord logRecord) {
+ private static LogEntry.@Nullable SourceLocation sourceLocationOf(ExtLogRecord logRecord) {
var sourceFileName = logRecord.getSourceFileName();
var sourceLineNumber = logRecord.getSourceLineNumber();
var sourceClassName = logRecord.getSourceClassName();
@@ -191,9 +188,10 @@ public class Formatter extends ExtFormatter {
var messagePrintWriter = new PrintWriter(messageStringWriter);
messagePrintWriter.append(this.formatMessage(logRecord));
- if (logRecord.getThrown() != null) {
+ var logRecordThrown = logRecord.getThrown();
+ if (logRecordThrown != null) {
messagePrintWriter.println();
- logRecord.getThrown().printStackTrace(messagePrintWriter);
+ logRecordThrown.printStackTrace(messagePrintWriter);
}
messagePrintWriter.close();
@@ -230,9 +228,9 @@ public class Formatter extends ExtFormatter {
private static class ProviderContext
implements LabelProvider.Context, StructuredParameterProvider.Context {
- private final String loggerName;
+ private final @Nullable String loggerName;
private final long sequenceNumber;
- private final String threadName;
+ private final @Nullable String threadName;
private ProviderContext(ExtLogRecord logRecord) {
loggerName = logRecord.getLoggerName();
@@ -241,7 +239,7 @@ public class Formatter extends ExtFormatter {
}
@Override
- public String loggerName() {
+ public @Nullable String loggerName() {
return loggerName;
}
@@ -251,7 +249,7 @@ public class Formatter extends ExtFormatter {
}
@Override
- public String threadName() {
+ public @Nullable String threadName() {
return threadName;
}
}
diff --git a/core/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/InsertId.java b/core/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/InsertId.java
index b55cf78..48b376c 100644
--- a/core/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/InsertId.java
+++ b/core/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/InsertId.java
@@ -5,17 +5,18 @@
package eu.mulk.quarkus.googlecloud.jsonlogging;
import java.util.Objects;
+import org.jspecify.annotations.Nullable;
/**
* A unique identifier for a log entry.
*
- * <p>Prevents the duplicate insertion of log entries. Also serves as a discriminator to order log entries that carry
- * the same time stamp.
+ * <p>Prevents the duplicate insertion of log entries. Also serves as a discriminator to order log
+ * entries that carry the same time stamp.
*
* <p>Will be generated by Google Cloud Logging if not provided.
*
- * <p>Instances of {@link InsertId} can be passed as log parameters to the {@code *f} family of logging
- * functions on {@link org.jboss.logging.Logger}.
+ * <p>Instances of {@link InsertId} can be passed as log parameters to the {@code *f} family of
+ * logging functions on {@link org.jboss.logging.Logger}.
*
* <p><strong>Example:</strong>
*
@@ -63,7 +64,7 @@ public final class InsertId {
}
@Override
- public boolean equals(Object obj) {
+ public boolean equals(@Nullable Object obj) {
if (obj == this) return true;
if (obj == null || obj.getClass() != this.getClass()) return false;
var that = (InsertId) obj;
diff --git a/core/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/KeyValueParameter.java b/core/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/KeyValueParameter.java
index a2c468b..9e16aab 100644
--- a/core/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/KeyValueParameter.java
+++ b/core/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/KeyValueParameter.java
@@ -10,6 +10,7 @@ import jakarta.json.spi.JsonProvider;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Objects;
+import org.jspecify.annotations.Nullable;
/**
* A simple single key–value pair forming a {@link StructuredParameter}.
@@ -168,7 +169,7 @@ public final class KeyValueParameter implements StructuredParameter {
}
@Override
- public boolean equals(Object obj) {
+ public boolean equals(@Nullable Object obj) {
if (obj == this) return true;
if (obj == null || obj.getClass() != this.getClass()) return false;
var that = (KeyValueParameter) obj;
diff --git a/core/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/Label.java b/core/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/Label.java
index d5a9000..2696185 100644
--- a/core/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/Label.java
+++ b/core/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/Label.java
@@ -5,6 +5,7 @@
package eu.mulk.quarkus.googlecloud.jsonlogging;
import java.util.Objects;
+import org.jspecify.annotations.Nullable;
/**
* A label usable to tag a log message.
@@ -78,7 +79,7 @@ public final class Label {
}
@Override
- public boolean equals(Object obj) {
+ public boolean equals(@Nullable Object obj) {
if (obj == this) return true;
if (obj == null || obj.getClass() != this.getClass()) return false;
var that = (Label) obj;
diff --git a/core/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/LabelProvider.java b/core/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/LabelProvider.java
index 0298042..2bc0349 100644
--- a/core/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/LabelProvider.java
+++ b/core/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/LabelProvider.java
@@ -5,6 +5,7 @@
package eu.mulk.quarkus.googlecloud.jsonlogging;
import java.util.Collection;
+import org.jspecify.annotations.Nullable;
/**
* A user-supplied provider for {@link Label}s.
@@ -52,7 +53,7 @@ public interface LabelProvider {
* @return a collection of {@link Label}s to add to each log entry that is logged.
* @see #getLabels(Context)
*/
- default Collection<Label> getLabels() {
+ default @Nullable Collection<Label> getLabels() {
return null;
}
@@ -63,7 +64,7 @@ public interface LabelProvider {
*
* @return a collection of {@link Label}s to add to each log entry that is logged.
*/
- default Collection<Label> getLabels(Context context) {
+ default @Nullable Collection<Label> getLabels(Context context) {
return getLabels();
}
diff --git a/core/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/LogEntry.java b/core/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/LogEntry.java
index 2d08c29..d335ee4 100644
--- a/core/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/LogEntry.java
+++ b/core/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/LogEntry.java
@@ -4,12 +4,12 @@
package eu.mulk.quarkus.googlecloud.jsonlogging;
-import io.smallrye.common.constraint.Nullable;
import jakarta.json.JsonString;
import jakarta.json.JsonValue;
import java.time.Instant;
import java.util.List;
import java.util.Map;
+import org.jspecify.annotations.Nullable;
/**
* A JSON log entry compatible with Google Cloud Logging.
@@ -27,15 +27,15 @@ final class LogEntry {
private final String message;
private final String severity;
private final Timestamp timestamp;
- @Nullable private final String trace;
- @Nullable private final String spanId;
- @Nullable private final SourceLocation sourceLocation;
+ private final @Nullable String trace;
+ private final @Nullable String spanId;
+ private final @Nullable SourceLocation sourceLocation;
private final Map<String, String> labels;
private final List<StructuredParameter> parameters;
private final Map<String, String> mappedDiagnosticContext;
- @Nullable private final String nestedDiagnosticContext;
- @Nullable private final String type;
- @Nullable private final String insertId;
+ private final @Nullable String nestedDiagnosticContext;
+ private final @Nullable String type;
+ private final @Nullable String insertId;
LogEntry(
String message,
@@ -66,9 +66,9 @@ final class LogEntry {
static final class SourceLocation {
- @Nullable private final String file;
- @Nullable private final String line;
- @Nullable private final String function;
+ private final @Nullable String file;
+ private final @Nullable String line;
+ private final @Nullable String function;
SourceLocation(@Nullable String file, @Nullable String line, @Nullable String function) {
this.file = file;
diff --git a/core/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/ProviderContext.java b/core/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/ProviderContext.java
index 08b399a..93f7a7a 100644
--- a/core/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/ProviderContext.java
+++ b/core/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/ProviderContext.java
@@ -5,6 +5,7 @@
package eu.mulk.quarkus.googlecloud.jsonlogging;
import org.jboss.logmanager.ExtLogRecord;
+import org.jspecify.annotations.Nullable;
/**
* Contextual data available to {@link StructuredParameterProvider} and {@link LabelProvider}.
@@ -19,7 +20,7 @@ public interface ProviderContext {
*
* @return {@link ExtLogRecord#getLoggerName()}.
*/
- String loggerName();
+ @Nullable String loggerName();
/**
* The {@link ExtLogRecord#getSequenceNumber()} property of the log record that is being
@@ -34,5 +35,5 @@ public interface ProviderContext {
*
* @return {@link ExtLogRecord#getThreadName()}.
*/
- String threadName();
+ @Nullable String threadName();
}
diff --git a/core/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/StructuredParameterProvider.java b/core/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/StructuredParameterProvider.java
index d78f0d8..c02516c 100644
--- a/core/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/StructuredParameterProvider.java
+++ b/core/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/StructuredParameterProvider.java
@@ -4,6 +4,8 @@
package eu.mulk.quarkus.googlecloud.jsonlogging;
+import org.jspecify.annotations.Nullable;
+
/**
* A user-supplied provider for {@link StructuredParameter}s.
*
@@ -58,7 +60,7 @@ public interface StructuredParameterProvider {
* @return a {@link StructuredParameter} to add to each log entry that is logged.
* @see #getParameter(Context)
*/
- default StructuredParameter getParameter() {
+ default @Nullable StructuredParameter getParameter() {
return null;
}
@@ -73,7 +75,7 @@ public interface StructuredParameterProvider {
*
* @return a {@link StructuredParameter} to add to each log entry that is logged.
*/
- default StructuredParameter getParameter(Context context) {
+ default @Nullable StructuredParameter getParameter(Context context) {
return getParameter();
}
diff --git a/core/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/package-info.java b/core/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/package-info.java
index a84f1fc..0ffe13c 100644
--- a/core/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/package-info.java
+++ b/core/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/package-info.java
@@ -198,4 +198,7 @@
* }
* }
*/
+@NullMarked
package eu.mulk.quarkus.googlecloud.jsonlogging;
+
+import org.jspecify.annotations.NullMarked;