Skip to content

Commit d678e64

Browse files
committed
Use lazy supplier
1 parent ea9944f commit d678e64

File tree

2 files changed

+14
-15
lines changed

2 files changed

+14
-15
lines changed

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

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

1919
import java.net.URL;
2020
import java.security.CodeSource;
21+
import org.apache.logging.log4j.util.Lazy;
2122

2223
/**
2324
* Resource information (i.e., the enclosing JAR file and its version) of a class.
@@ -26,21 +27,15 @@ final class ClassResourceInfo {
2627

2728
static final ClassResourceInfo UNKNOWN = new ClassResourceInfo();
2829

29-
private final String exactnessPrefix;
30-
31-
private final String location;
32-
33-
private final String version;
30+
private final Lazy<String> text;
3431

3532
final Class<?> clazz;
3633

3734
/**
3835
* Constructs an instance modelling an unknown class resource.
3936
*/
4037
private ClassResourceInfo() {
41-
this.exactnessPrefix = "~";
42-
this.location = "?";
43-
this.version = "?";
38+
this.text = Lazy.value("~[?:?]");
4439
this.clazz = null;
4540
}
4641

@@ -50,9 +45,14 @@ private ClassResourceInfo() {
5045
*/
5146
ClassResourceInfo(final Class<?> clazz, final boolean exact) {
5247
this.clazz = clazz;
53-
this.exactnessPrefix = exact ? "" : "~";
54-
this.location = getLocation(clazz);
55-
this.version = getVersion(clazz);
48+
this.text = Lazy.lazy(() -> getText(clazz, exact));
49+
}
50+
51+
private static String getText(final Class<?> clazz, final boolean exact) {
52+
final String exactnessPrefix = exact ? "" : "~";
53+
final String location = getLocation(clazz);
54+
final String version = getVersion(clazz);
55+
return String.format("%s[%s:%s]", exactnessPrefix, location, version);
5656
}
5757

5858
private static String getLocation(final Class<?> clazz) {
@@ -88,6 +88,6 @@ private static String getVersion(final Class<?> clazz) {
8888

8989
@Override
9090
public String toString() {
91-
return String.format("%s[%s:%s]", exactnessPrefix, location, version);
91+
return text.get();
9292
}
9393
}

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@
1616
*/
1717
package org.apache.logging.log4j.core.pattern;
1818

19-
import org.apache.logging.log4j.util.LoaderUtil;
20-
import org.apache.logging.log4j.util.StackLocatorUtil;
21-
2219
import java.util.ArrayDeque;
2320
import java.util.Collections;
2421
import java.util.Deque;
@@ -30,6 +27,8 @@
3027
import java.util.Queue;
3128
import java.util.Set;
3229
import java.util.stream.Stream;
30+
import org.apache.logging.log4j.util.LoaderUtil;
31+
import org.apache.logging.log4j.util.StackLocatorUtil;
3332

3433
/**
3534
* {@link ThrowableStackTraceRenderer} variant where the rendered {@link StackTraceElement}s are enriched with the enclosing JAR file and its version information, if available.

0 commit comments

Comments
 (0)