Skip to content

Commit 027009e

Browse files
committed
Sync JsonWriter with the one in 2.x
1 parent ec93d18 commit 027009e

File tree

1 file changed

+9
-10
lines changed
  • log4j-layout-template-json/src/main/java/org/apache/logging/log4j/layout/template/json/util

1 file changed

+9
-10
lines changed

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

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import java.util.Objects;
2525
import java.util.function.BiConsumer;
2626
import org.apache.logging.log4j.util.IndexedReadOnlyStringMap;
27-
import org.apache.logging.log4j.util.Lazy;
2827
import org.apache.logging.log4j.util.StringBuilderFormattable;
2928
import org.apache.logging.log4j.util.StringMap;
3029

@@ -66,7 +65,9 @@ public final class JsonWriter implements AutoCloseable, Cloneable {
6665
* character to use after backslash; and negative values, that generic
6766
* (backslash - u) escaping is to be used.
6867
*/
69-
private static final Lazy<int[]> ESC_CODES = Lazy.pure(() -> {
68+
private static final int[] ESC_CODES;
69+
70+
static {
7071
final int[] table = new int[128];
7172
// Control chars need generic escape sequence
7273
for (int i = 0; i < 32; ++i) {
@@ -82,8 +83,8 @@ public final class JsonWriter implements AutoCloseable, Cloneable {
8283
table[0x0C] = 'f';
8384
table[0x0A] = 'n';
8485
table[0x0D] = 'r';
85-
return table;
86-
});
86+
ESC_CODES = table;
87+
}
8788

8889
private final char[] quoteBuffer;
8990

@@ -582,12 +583,11 @@ private void quoteString(final CharSequence seq, final int offset, final int len
582583
length > 0 && Character.isHighSurrogate(seq.charAt(offset + length - 1)) ? -1 : 0;
583584
final int limit = offset + length + surrogateCorrection;
584585
int i = offset;
585-
final int[] escCodes = ESC_CODES.get();
586586
outer:
587587
while (i < limit) {
588588
while (true) {
589589
final char c = seq.charAt(i);
590-
if (c < escCodes.length && escCodes[c] != 0) {
590+
if (c < ESC_CODES.length && ESC_CODES[c] != 0) {
591591
break;
592592
}
593593
stringBuilder.append(c);
@@ -596,7 +596,7 @@ private void quoteString(final CharSequence seq, final int offset, final int len
596596
}
597597
}
598598
final char d = seq.charAt(i++);
599-
final int escCode = escCodes[d];
599+
final int escCode = ESC_CODES[d];
600600
final int quoteBufferLength = escCode < 0 ? quoteNumeric(d) : quoteNamed(escCode);
601601
stringBuilder.append(quoteBuffer, 0, quoteBufferLength);
602602
}
@@ -646,12 +646,11 @@ private void quoteString(final char[] buffer, final int offset, final int length
646646
final int surrogateCorrection = length > 0 && Character.isHighSurrogate(buffer[offset + length - 1]) ? -1 : 0;
647647
final int limit = offset + length + surrogateCorrection;
648648
int i = offset;
649-
final int[] escCodes = ESC_CODES.get();
650649
outer:
651650
while (i < limit) {
652651
while (true) {
653652
final char c = buffer[i];
654-
if (c < escCodes.length && escCodes[c] != 0) {
653+
if (c < ESC_CODES.length && ESC_CODES[c] != 0) {
655654
break;
656655
}
657656
stringBuilder.append(c);
@@ -660,7 +659,7 @@ private void quoteString(final char[] buffer, final int offset, final int length
660659
}
661660
}
662661
final char d = buffer[i++];
663-
final int escCode = escCodes[d];
662+
final int escCode = ESC_CODES[d];
664663
final int quoteBufferLength = escCode < 0 ? quoteNumeric(d) : quoteNamed(escCode);
665664
stringBuilder.append(quoteBuffer, 0, quoteBufferLength);
666665
}

0 commit comments

Comments
 (0)