Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not completely swallow the cdi exception on error #5299

Merged
merged 1 commit into from
Apr 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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