Skip to content

Commit

Permalink
Fix transformer allocations being cached even when dependent scoped
Browse files Browse the repository at this point in the history
  • Loading branch information
Col-E committed Nov 11, 2024
1 parent 3252f68 commit e8d0108
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@
import jakarta.inject.Inject;
import org.slf4j.Logger;
import software.coley.collections.Unchecked;
import software.coley.recaf.Bootstrap;
import software.coley.recaf.analytics.logging.Logging;
import software.coley.recaf.services.Service;

import java.util.HashMap;
import java.util.IdentityHashMap;
import java.util.Map;
import java.util.function.Consumer;
import java.util.function.Supplier;

/**
Expand Down Expand Up @@ -43,7 +45,12 @@ public TransformationManager(@Nonnull TransformationManagerConfig config, @Nonnu
for (Instance.Handle<JvmClassTransformer> handle : jvmTransformers.handles()) {
Bean<JvmClassTransformer> bean = handle.getBean();
Class<? extends JvmClassTransformer> transformerClass = Unchecked.cast(bean.getBeanClass());
jvmTransformerSuppliers.put(transformerClass, handle::get);
jvmTransformerSuppliers.put(transformerClass, () -> {
// Even though our transformers may be @Dependent scoped, we need to do a new lookup each time we want
// a new instance to get our desired scope behavior. If we re-use the instance handle that is injected
// here then even @Dependent scoped beans will yield the same instance again and again.
return Bootstrap.get().get(transformerClass);
});
}
}

Expand Down

0 comments on commit e8d0108

Please sign in to comment.