Skip to content

Commit b2639e1

Browse files
committedMar 17, 2023
8304164: jdk/classfile/CorpusTest.java still fails after JDK-8303910
Reviewed-by: jpai
1 parent 620564a commit b2639e1

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed
 

‎src/java.base/share/classes/jdk/internal/classfile/impl/ClassHierarchyImpl.java

+9-3
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,10 @@ public boolean isAssignableFrom(ClassDesc thisClass, ClassDesc fromClass) {
110110

111111
public static final class CachedClassHierarchyResolver implements ClassHierarchyResolver {
112112

113+
//this instance should never appear in the cache nor leak out
114+
private static final ClassHierarchyResolver.ClassHierarchyInfo NOPE =
115+
new ClassHierarchyResolver.ClassHierarchyInfo(null, false, null);
116+
113117
private final Function<ClassDesc, InputStream> streamProvider;
114118
private final Map<ClassDesc, ClassHierarchyResolver.ClassHierarchyInfo> resolvedCache;
115119

@@ -124,9 +128,11 @@ public CachedClassHierarchyResolver(Function<ClassDesc, InputStream> classStream
124128
// empty ClInfo is stored in case of an exception to avoid repeated scanning failures
125129
@Override
126130
public ClassHierarchyResolver.ClassHierarchyInfo getClassInfo(ClassDesc classDesc) {
127-
var res = resolvedCache.get(classDesc);
128-
//additional test for null value is important to avoid repeated resolution attempts
129-
if (res == null && !resolvedCache.containsKey(classDesc)) {
131+
//using NOPE to distinguish between null value and non-existent record in the cache
132+
//this code is on JDK bootstrap critical path, so cannot use lambdas here
133+
var res = resolvedCache.getOrDefault(classDesc, NOPE);
134+
if (res == NOPE) {
135+
res = null;
130136
var ci = streamProvider.apply(classDesc);
131137
if (ci != null) {
132138
try (var in = new DataInputStream(new BufferedInputStream(ci))) {

0 commit comments

Comments
 (0)
Please sign in to comment.