Prevent unsafe publication of not full initialized instance

#KTIJ-22182
This commit is contained in:
Vladimir Dolzhenko
2022-11-22 12:17:24 +01:00
committed by Space Team
parent 067036c162
commit a8bef8ac81
2 changed files with 9 additions and 6 deletions
@@ -94,7 +94,10 @@ public class AnnotationResolverImpl extends AnnotationResolver {
for (KtAnnotationEntry entryElement : annotationEntryElements) {
AnnotationDescriptor descriptor = trace.get(BindingContext.ANNOTATION, entryElement);
if (descriptor == null) {
descriptor = new LazyAnnotationDescriptor(new LazyAnnotationsContextImpl(this, storageManager, trace, scope), entryElement);
LazyAnnotationDescriptor lazyAnnotationDescriptor =
new LazyAnnotationDescriptor(new LazyAnnotationsContextImpl(this, storageManager, trace, scope), entryElement);
lazyAnnotationDescriptor.recordToTrace();
descriptor = lazyAnnotationDescriptor;
}
if (shouldResolveArguments) {
ForceResolveUtil.forceResolveAllContents(descriptor);
@@ -60,7 +60,7 @@ class LazyAnnotations(
override fun isEmpty() = annotationEntries.isEmpty()
private val annotation = c.storageManager.createMemoizedFunction { entry: KtAnnotationEntry ->
c.trace.get(BindingContext.ANNOTATION, entry) ?: LazyAnnotationDescriptor(c, entry)
c.trace.get(BindingContext.ANNOTATION, entry) ?: LazyAnnotationDescriptor(c, entry).also { it.recordToTrace() }
}
override fun iterator(): Iterator<AnnotationDescriptor> = annotationEntries.asSequence().map(annotation).iterator()
@@ -78,10 +78,6 @@ class LazyAnnotationDescriptor(
val annotationEntry: KtAnnotationEntry
) : AnnotationDescriptor, LazyEntity {
init {
c.trace.record(BindingContext.ANNOTATION, annotationEntry, this)
}
override val type by c.storageManager.createLazyValue(
computable = lazy@{
val annotationType = c.annotationResolver.resolveAnnotationType(scope, annotationEntry, c.trace)
@@ -133,6 +129,10 @@ class LazyAnnotationDescriptor(
allValueArguments
}
fun recordToTrace() {
c.trace.record(BindingContext.ANNOTATION, annotationEntry, this)
}
private class FileDescriptorForVisibilityChecks(
private val source: SourceElement,
private val containingDeclaration: PackageFragmentDescriptor