Skip to content

Commit

Permalink
Merge pull request #40267 from mkouba/arc-eager-instance-npe
Browse files Browse the repository at this point in the history
ArC: prevent NPE when EagerInstanceHandle.UNAVAILABLE is closed
  • Loading branch information
mkouba authored Apr 25, 2024
2 parents e2315ec + 6ecefbe commit 438c23e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ abstract class AbstractInstanceHandle<T> implements InstanceHandle<T> {
private static final AtomicIntegerFieldUpdater<AbstractInstanceHandle> DESTROYED_UPDATER = AtomicIntegerFieldUpdater
.newUpdater(AbstractInstanceHandle.class, "destroyed");

private final InjectableBean<T> bean;
protected final InjectableBean<T> bean;
private final CreationalContext<T> creationalContext;
private final CreationalContext<?> parentCreationalContext;
private final Consumer<T> destroyLogic;
Expand Down Expand Up @@ -56,7 +56,7 @@ public void destroy() {
if (isInstanceCreated() && DESTROYED_UPDATER.compareAndSet(this, 0, 1)) {
if (destroyLogic != null) {
destroyLogic.accept(instanceInternal());
} else {
} else if (bean != null) {
if (bean.getScope().equals(Dependent.class)) {
destroyInternal();
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
import io.quarkus.arc.InstanceHandle;

/**
* Instance handle that is initialized eagerly when created.
*
* @param <T>
* @see LazyInstanceHandle
*/
class EagerInstanceHandle<T> extends AbstractInstanceHandle<T> {

Expand All @@ -34,7 +36,7 @@ public static final <T> InstanceHandle<T> unavailable() {

@Override
protected boolean isInstanceCreated() {
return true;
return instance != null;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
import io.quarkus.arc.InjectableBean;

/**
* Instance handle that is initialized lazily when first used.
*
* @param <T>
* @see EagerInstanceHandle
*/
class LazyInstanceHandle<T> extends AbstractInstanceHandle<T> {

Expand Down

0 comments on commit 438c23e

Please sign in to comment.