Skip to content

Commit

Permalink
Do not completely swallow the cdi exception on error
Browse files Browse the repository at this point in the history
Signed-off-by: jansupol <jan.supol@oracle.com>
  • Loading branch information
jansupol committed Apr 27, 2023
1 parent 34349dc commit 131519e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, 2021 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
Expand All @@ -16,10 +16,13 @@

package org.glassfish.jersey.ext.cdi1x.internal;

import java.io.PrintWriter;
import java.io.StringWriter;
import java.lang.annotation.Annotation;
import java.util.Iterator;
import java.util.NoSuchElementException;
import java.util.Set;
import java.util.logging.Logger;

import javax.enterprise.context.spi.Contextual;
import javax.enterprise.context.spi.CreationalContext;
Expand All @@ -44,6 +47,8 @@
*/
public abstract class AbstractCdiBeanSupplier<T> implements DisposableSupplier<T> {

private static final Logger LOGGER = Logger.getLogger(AbstractCdiBeanSupplier.class.getName());

final Class<T> clazz;
final InstanceManager<T> referenceProvider;
final Annotation[] qualifiers;
Expand Down Expand Up @@ -115,7 +120,16 @@ private static <T> T produce(InjectionTarget<T> target, CreationalContext<T> ctx
try {
return target.produce(ctx);
} catch (Exception e) {
return im.create(clazz);
LOGGER.fine(LocalizationMessages.CDI_FAILED_LOADING(clazz, e.getMessage()));
try {
return im.create(clazz);
} catch (RuntimeException re) {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
e.printStackTrace(pw);
LOGGER.warning(LocalizationMessages.CDI_FAILED_LOADING(clazz, sw.toString()));
throw re;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2013, 2018 Oracle and/or its affiliates. All rights reserved.
# Copyright (c) 2013, 2023 Oracle and/or its affiliates. All rights reserved.
# Copyright (c) 2018 Payara Foundation and/or its affiliates. All rights reserved.
#
# This program and the accompanying materials are made available under the
Expand All @@ -21,6 +21,7 @@ cdi.class.being.checked=Class, {0}, is being checked with Jersey CDI component p
cdi.class.bound.with.cdi=Class, {0}, has been bound by Jersey CDI component provider.
cdi.hk2.bean.registered=CDI beans backed by HK2 have been registered for the following types: {0}
cdi.lookup.failed=Error when lookup instance of class, {0}, in CDI.
cdi.failed.loading=CDI failed instantiating the class {0} with {1}, falling back to HK2.
cdi.multiple.locators.into.simple.app=Trying to register multiple service locators into single service locator application.
cdi.provider.initialized=Jersey CDI component provider initialized.
cdi.request.scoped.components.recognized=The following CDI types were recognized as request scoped components in Jersey: {0}.
Expand Down

0 comments on commit 131519e

Please sign in to comment.