Skip to content

Commit 3fa242a

Browse files
committed
remove String.format
1 parent a7daffe commit 3fa242a

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/ClassResourceInfo.java

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
import java.net.URL;
2020
import java.security.CodeSource;
21-
import org.apache.logging.log4j.util.Lazy;
21+
import java.util.function.Consumer;
2222

2323
/**
2424
* Resource information (i.e., the enclosing JAR file and its version) of a class.
@@ -27,32 +27,35 @@ final class ClassResourceInfo {
2727

2828
static final ClassResourceInfo UNKNOWN = new ClassResourceInfo();
2929

30-
private final Lazy<String> textRef;
30+
private final Consumer<StringBuilder> consumer;
3131

3232
final Class<?> clazz;
3333

3434
/**
3535
* Constructs an instance modelling an unknown class resource.
3636
*/
3737
private ClassResourceInfo() {
38-
this.textRef = Lazy.value("~[?:?]");
39-
this.clazz = null;
38+
this.consumer = (buffer) -> buffer.append("~[?:?]");
39+
clazz = null;
4040
}
4141

4242
/**
4343
* @param clazz the class
4444
* @param exact {@code true}, if the class was obtained via reflection; {@code false}, otherwise
4545
*/
4646
ClassResourceInfo(final Class<?> clazz, final boolean exact) {
47-
this.clazz = clazz;
48-
this.textRef = Lazy.lazy(() -> getText(clazz, exact));
49-
}
50-
51-
private static String getText(final Class<?> clazz, final boolean exact) {
5247
final String exactnessPrefix = exact ? "" : "~";
5348
final String location = getLocation(clazz);
5449
final String version = getVersion(clazz);
55-
return String.format("%s[%s:%s]", exactnessPrefix, location, version);
50+
this.consumer = (buffer) -> {
51+
buffer.append(exactnessPrefix);
52+
buffer.append("[");
53+
buffer.append(location);
54+
buffer.append(":");
55+
buffer.append(version);
56+
buffer.append("]");
57+
};
58+
this.clazz = clazz;
5659
}
5760

5861
private static String getLocation(final Class<?> clazz) {
@@ -86,8 +89,7 @@ private static String getVersion(final Class<?> clazz) {
8689
return "?";
8790
}
8891

89-
@Override
90-
public String toString() {
91-
return textRef.get();
92+
public void render(final StringBuilder buffer) {
93+
this.consumer.accept(buffer);
9294
}
9395
}

log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/ThrowableExtendedStackTraceRenderer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ void renderStackTraceElement(
7575
context.classResourceInfoByName.get(stackTraceElement.getClassName());
7676
if (classResourceInfo != null) {
7777
buffer.append(' ');
78-
buffer.append(classResourceInfo);
78+
classResourceInfo.render(buffer);
7979
}
8080
buffer.append(lineSeparator);
8181
}

0 commit comments

Comments
 (0)