Skip to content

Commit b1113c7

Browse files
committed
Fix static analysis issues
1 parent 3254858 commit b1113c7

File tree

8 files changed

+17
-33
lines changed

8 files changed

+17
-33
lines changed

log4j-layout-template-json-test/src/test/java/org/apache/logging/log4j/layout/template/json/NestedLoggingTest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
*/
1717
package org.apache.logging.log4j.layout.template.json;
1818

19+
import java.io.Serial;
1920
import java.nio.charset.StandardCharsets;
2021
import java.util.List;
2122
import java.util.stream.Collectors;
@@ -37,6 +38,9 @@ public class NestedLoggingTest {
3738

3839
private static final class ThrowableLoggingInGetMessage extends RuntimeException {
3940

41+
@Serial
42+
private static final long serialVersionUID = 42L;
43+
4044
private final Logger logger;
4145

4246
private ThrowableLoggingInGetMessage(final Logger logger) {

log4j-layout-template-json-test/src/test/java/org/apache/logging/log4j/layout/template/json/resolver/LevelResolverTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,13 @@
1616
*/
1717
package org.apache.logging.log4j.layout.template.json.resolver;
1818

19-
import static org.apache.logging.log4j.layout.template.json.TestHelpers.*;
19+
import static org.apache.logging.log4j.layout.template.json.TestHelpers.CONFIGURATION;
20+
import static org.apache.logging.log4j.layout.template.json.TestHelpers.asMap;
21+
import static org.apache.logging.log4j.layout.template.json.TestHelpers.usingSerializedLogEventAccessor;
22+
import static org.apache.logging.log4j.layout.template.json.TestHelpers.writeJson;
2023
import static org.assertj.core.api.Assertions.assertThat;
2124

2225
import org.apache.logging.log4j.Level;
23-
import org.apache.logging.log4j.Marker;
24-
import org.apache.logging.log4j.MarkerManager;
2526
import org.apache.logging.log4j.core.LogEvent;
2627
import org.apache.logging.log4j.core.impl.Log4jLogEvent;
2728
import org.apache.logging.log4j.layout.template.json.JsonTemplateLayout;
@@ -46,7 +47,6 @@ void should_work_with_custom_levels() {
4647
.build();
4748

4849
// Create the log event.
49-
final Marker marker = MarkerManager.getMarker("MARKER");
5050
Level level = Level.forName("CUSTOM_LEVEL", 250);
5151
final LogEvent logEvent = Log4jLogEvent.newBuilder().setLevel(level).build();
5252

log4j-layout-template-json-test/src/test/java/org/apache/logging/log4j/layout/template/json/resolver/MessageResolverTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
class MessageResolverTest {
4444

4545
/**
46-
* @see <a href="https://issues.apache.org/jira/browse/LOG4J2-3080">LOG4J2-3080</a>
46+
* Tests the inconsistent <code>fallbackKey</code> behaviour described in <a href="https://issues.apache.org/jira/browse/LOG4J2-3080">LOG4J2-3080</a>.
4747
*/
4848
@Test
4949
@LoggerContextSource("messageFallbackKeyUsingJsonTemplateLayout.xml")

log4j-layout-template-json-test/src/test/java/org/apache/logging/log4j/layout/template/json/resolver/StackTraceStringResolverTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import org.junit.jupiter.api.Nested;
4040
import org.junit.jupiter.api.Test;
4141

42+
@SuppressWarnings("StaticAssignmentOfThrowable")
4243
class StackTraceStringResolverTest {
4344

4445
////////////////////////////////////////////////////////////////////////////

log4j-layout-template-json-test/src/test/java/org/apache/logging/log4j/layout/template/json/resolver/TimestampResolverTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
class TimestampResolverTest {
2929

3030
/**
31-
* @see <a href="https://issues.apache.org/jira/browse/LOG4J2-3183">LOG4J2-3183</a>
31+
* Tests epoch nanoseconds do not overlap as reported in <a href="https://issues.apache.org/jira/browse/LOG4J2-3183">LOG4J2-3183</a>.
3232
*/
3333
@Test
3434
void epoch_nanos_should_not_overlap() {

log4j-layout-template-json-test/src/test/java/org/apache/logging/log4j/layout/template/json/util/JsonWriterTest.java

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -433,12 +433,7 @@ void test_writeString_emitter_excessive_string() {
433433
void test_writeString_emitter_excessive_string_ending_with_high_surrogate() {
434434
withLockedWriter(writer -> {
435435
final int maxStringLength = writer.getMaxStringLength();
436-
@SuppressWarnings("StringBufferReplaceableByString")
437-
final String excessiveString = new StringBuilder()
438-
.append("x".repeat(maxStringLength - 1))
439-
.append(HI_SURROGATE)
440-
.append(LO_SURROGATE)
441-
.toString();
436+
final String excessiveString = "x".repeat(maxStringLength - 1) + HI_SURROGATE + LO_SURROGATE;
442437
final String expectedJson =
443438
"\"" + "x".repeat(maxStringLength - 1) + writer.getTruncatedStringSuffix() + '"';
444439
final BiConsumer<StringBuilder, String> emitter = StringBuilder::append;
@@ -479,12 +474,7 @@ void test_writeString_formattable_excessive_string() {
479474
void test_writeString_formattable_excessive_string_ending_with_high_surrogate() {
480475
withLockedWriter(writer -> {
481476
final int maxStringLength = writer.getMaxStringLength();
482-
@SuppressWarnings("StringBufferReplaceableByString")
483-
final String excessiveString = new StringBuilder()
484-
.append("x".repeat(maxStringLength - 1))
485-
.append(HI_SURROGATE)
486-
.append(LO_SURROGATE)
487-
.toString();
477+
final String excessiveString = "x".repeat(maxStringLength - 1) + HI_SURROGATE + LO_SURROGATE;
488478
final String expectedJson =
489479
"\"" + "x".repeat(maxStringLength - 1) + writer.getTruncatedStringSuffix() + '"';
490480
final String actualJson =
@@ -549,12 +539,7 @@ void test_writeString_excessive_seq() {
549539
void test_writeString_excessive_seq_ending_with_high_surrogate() {
550540
withLockedWriter(writer -> {
551541
final int maxStringLength = writer.getMaxStringLength();
552-
@SuppressWarnings("StringBufferReplaceableByString")
553-
final CharSequence seq = new StringBuilder()
554-
.append("x".repeat(maxStringLength - 1))
555-
.append(HI_SURROGATE)
556-
.append(LO_SURROGATE)
557-
.toString();
542+
final CharSequence seq = "x".repeat(maxStringLength - 1) + HI_SURROGATE + LO_SURROGATE;
558543
final String expectedJson =
559544
"\"" + "x".repeat(maxStringLength - 1) + writer.getTruncatedStringSuffix() + '"';
560545
final String actualJson = writer.use(() -> writer.writeString(seq));
@@ -614,13 +599,7 @@ void test_writeString_excessive_buffer() {
614599
void test_writerString_excessive_buffer_ending_with_high_surrogate() {
615600
withLockedWriter(writer -> {
616601
final int maxStringLength = writer.getMaxStringLength();
617-
@SuppressWarnings("StringBufferReplaceableByString")
618-
final char[] buffer = new StringBuilder()
619-
.append("x".repeat(maxStringLength - 1))
620-
.append(HI_SURROGATE)
621-
.append(LO_SURROGATE)
622-
.toString()
623-
.toCharArray();
602+
final char[] buffer = ("x".repeat(maxStringLength - 1) + HI_SURROGATE + LO_SURROGATE).toCharArray();
624603
final String expectedJson =
625604
"\"" + "x".repeat(maxStringLength - 1) + writer.getTruncatedStringSuffix() + '"';
626605
final String actualJson = writer.use(() -> writer.writeString(buffer));

log4j-layout-template-json/src/main/java/org/apache/logging/log4j/layout/template/json/resolver/MessageResolverFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import org.apache.logging.log4j.plugins.PluginFactory;
2222

2323
/**
24-
* @see MessageResolver
24+
* A {@link MessageResolver} factory.
2525
*/
2626
@Namespace(TemplateResolverFactory.CATEGORY)
2727
@Plugin("MessageResolverFactory")

log4j-layout-template-json/src/main/java/org/apache/logging/log4j/layout/template/json/util/JsonWriter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -700,7 +700,7 @@ private void writeNumber(final Number number) {
700700
} else {
701701
final long longNumber = number.longValue();
702702
final double doubleValue = number.doubleValue();
703-
if (Double.compare(longNumber, doubleValue) == 0) {
703+
if (Double.compare((double) longNumber, doubleValue) == 0) {
704704
writeNumber(longNumber);
705705
} else {
706706
writeNumber(doubleValue);

0 commit comments

Comments
 (0)