You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by ju...@apache.org on 2026/04/19 15:41:53 UTC
(tomee) branch main updated: TOMEE-4600 - remove openejb.cache.cdi-type-resolution-failure
This is an automated email from the ASF dual-hosted git repository.
jungm pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tomee.git
The following commit(s) were added to refs/heads/main by this push:
new 32efa5d2f2 TOMEE-4600 - remove openejb.cache.cdi-type-resolution-failure
32efa5d2f2 is described below
commit 32efa5d2f2888572d8b788338e980a5301d8e8ea
Author: Markus Jung <ju...@apache.org>
AuthorDate: Thu Apr 16 07:55:38 2026 +0200
TOMEE-4600 - remove openejb.cache.cdi-type-resolution-failure
---
.../org/apache/openejb/cdi/AppBeanManager.java | 30 -----
.../org/apache/openejb/cdi/AppWebBeansContext.java | 53 --------
.../openejb/cdi/ThreadSingletonServiceImpl.java | 10 +-
.../openejb/cdi/WebAppInjectionResolver.java | 133 ---------------------
.../org/apache/openejb/cdi/WebappBeanManager.java | 1 -
.../openejb/cdi/InjectionResolverCacheTest.java | 102 ----------------
6 files changed, 1 insertion(+), 328 deletions(-)
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/cdi/AppBeanManager.java b/container/openejb-core/src/main/java/org/apache/openejb/cdi/AppBeanManager.java
deleted file mode 100755
index 9da6e6b1e9..0000000000
--- a/container/openejb-core/src/main/java/org/apache/openejb/cdi/AppBeanManager.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.openejb.cdi;
-
-import org.apache.openejb.util.reflection.Reflections;
-import org.apache.webbeans.config.WebBeansContext;
-import org.apache.webbeans.container.BeanManagerImpl;
-
-public class AppBeanManager extends BeanManagerImpl {
-
- public AppBeanManager(final WebBeansContext ctx) {
- super(ctx);
- Reflections.set(this, "injectionResolver", new WebAppInjectionResolver(ctx));
- }
-}
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/cdi/AppWebBeansContext.java b/container/openejb-core/src/main/java/org/apache/openejb/cdi/AppWebBeansContext.java
deleted file mode 100755
index 5dccb93ced..0000000000
--- a/container/openejb-core/src/main/java/org/apache/openejb/cdi/AppWebBeansContext.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.openejb.cdi;
-
-import org.apache.webbeans.config.WebBeansContext;
-import org.apache.webbeans.container.BeanManagerImpl;
-import org.apache.webbeans.container.InjectableBeanManager;
-
-import java.util.Map;
-import java.util.Properties;
-
-public class AppWebBeansContext extends WebBeansContext {
- private final InjectableBeanManager ibm;
- private BeanManagerImpl bm;
-
- public AppWebBeansContext(final Map<Class<?>, Object> services, final Properties properties) {
- super(services, properties);
- ibm = new InjectableBeanManager(getBeanManagerImpl());
- }
-
- @Override
- public InjectableBeanManager getInjectableBeanManager() {
- return ibm;
- }
-
- @SuppressWarnings("PMD.DoubleCheckedLocking")
- @Override
- public BeanManagerImpl getBeanManagerImpl() {
- if (bm == null) { // should be done in the constructor
- synchronized (this) {
- if (bm == null) {
- bm = new AppBeanManager(this);
- }
- }
- }
- return bm;
- }
-}
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/cdi/ThreadSingletonServiceImpl.java b/container/openejb-core/src/main/java/org/apache/openejb/cdi/ThreadSingletonServiceImpl.java
index e44cd0b385..b3240609b8 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/cdi/ThreadSingletonServiceImpl.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/cdi/ThreadSingletonServiceImpl.java
@@ -235,15 +235,7 @@ public class ThreadSingletonServiceImpl implements ThreadSingletonService {
Object old = null;
try {
if (startupObject.getWebContext() == null) {
- final boolean cacheResolutionFailure = Boolean.parseBoolean(
- SystemInstance.get().getProperty("openejb.cache.cdi-type-resolution-failure", "false"));
-
- if (cacheResolutionFailure) {
- webBeansContext = new AppWebBeansContext(services, properties);
- } else {
- webBeansContext = new WebBeansContext(services, properties);
- }
-
+ webBeansContext = new WebBeansContext(services, properties);
appContext.set(WebBeansContext.class, webBeansContext);
} else {
webBeansContext = new WebappWebBeansContext(services, properties, appContext.getWebBeansContext());
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/cdi/WebAppInjectionResolver.java b/container/openejb-core/src/main/java/org/apache/openejb/cdi/WebAppInjectionResolver.java
deleted file mode 100644
index 72b4fa4d07..0000000000
--- a/container/openejb-core/src/main/java/org/apache/openejb/cdi/WebAppInjectionResolver.java
+++ /dev/null
@@ -1,133 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.openejb.cdi;
-
-import org.apache.openejb.loader.SystemInstance;
-import org.apache.openejb.util.LogCategory;
-import org.apache.openejb.util.Logger;
-import org.apache.webbeans.config.WebBeansContext;
-import org.apache.webbeans.container.BeanCacheKey;
-import org.apache.webbeans.container.InjectionResolver;
-import org.apache.webbeans.spi.BDABeansXmlScanner;
-import org.apache.webbeans.spi.ScannerService;
-
-import jakarta.enterprise.inject.spi.AnnotatedType;
-import jakarta.enterprise.inject.spi.Bean;
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Type;
-import java.util.Collections;
-import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-
-public class WebAppInjectionResolver extends InjectionResolver {
- private static final Logger LOGGER = Logger.getInstance(LogCategory.OPENEJB, WebAppInjectionResolver.class);
- private final WebBeansContext context;
-
- private final boolean cacheResolutionFailure = Boolean.parseBoolean(SystemInstance.get().getProperty("openejb.cache.cdi-type-resolution-failure", "false"));
-
- private boolean startup;
-
- private final Set<BeanCacheKey> resolutionFailures = ConcurrentHashMap.newKeySet();
-
- public WebAppInjectionResolver(final WebBeansContext ctx) {
- super(ctx);
- context = ctx;
- startup = true;
- }
-
- @Override
- public Set<Bean<?>> implResolveByType(final boolean delegate, final Type injectionPointType, final Class<?> injectionPointClass, final Annotation... qualifiers) {
- // OWB will cache instances where the resolution by type is successful, but does not when it fails
- // The upshot is that if resolution happens again, the InjectionResolver will need to attempt
- // resolution again, before then trying implResolveByType() on the context.getParent() InjectionResolver,
- // and this will happen each and every time the resolution is attempted at runtime.
- //
- // This code attempts to cache lookup failures that happen outside of the startup phase. Caching resolution
- // failures should NOT be done during startup.
- //
- // The default for this behaviour is "off", and simply delegate to OWB, unless it is turned on.
-
- Set<Bean<?>> set;
- if (!startup && cacheResolutionFailure) {
- final ScannerService scannerService = context.getScannerService();
- String bdaBeansXMLFilePath = null;
- if (scannerService.isBDABeansXmlScanningEnabled()) {
- bdaBeansXMLFilePath = getBDABeansXMLPath(injectionPointClass);
- }
-
- final BeanCacheKey cacheKey = new BeanCacheKey(delegate, injectionPointType, bdaBeansXMLFilePath, this::findQualifierModel, qualifiers);
-
- if (resolutionFailures.contains(cacheKey)) {
- if (LOGGER.isDebugEnabled()) {
- LOGGER.debug("Resolution of " + cacheKey + " has previously failed, returning empty set from cache");
- }
- set = Collections.emptySet();
- } else {
- set = super.implResolveByType(delegate, injectionPointType, injectionPointClass, qualifiers);
- if (set.isEmpty()) {
- if (LOGGER.isDebugEnabled()) {
- LOGGER.debug("Caching resolution failure of " + cacheKey);
- }
- resolutionFailures.add(cacheKey);
- }
- }
- } else {
- set = super.implResolveByType(delegate, injectionPointType, injectionPointClass, qualifiers);
- }
-
- if (context instanceof WebappWebBeansContext wwbc) {
- if (set.isEmpty() && wwbc.getParent() != null) {
- if (LOGGER.isDebugEnabled()) {
- LOGGER.debug("Resolution of " + injectionPointType.getTypeName() + " from context failed, trying to resolve from parent context");
- }
- return wwbc.getParent().getBeanManagerImpl().getInjectionResolver().implResolveByType(delegate, injectionPointType, injectionPointClass, qualifiers);
- }
- }
- return set;
- }
-
- private String getBDABeansXMLPath(Class<?> injectionPointBeanClass) {
- if (injectionPointBeanClass == null) {
- return null;
- }
-
- ScannerService scannerService = context.getScannerService();
- BDABeansXmlScanner beansXMLScanner = scannerService.getBDABeansXmlScanner();
- return beansXMLScanner.getBeansXml(injectionPointBeanClass);
- }
-
- private AnnotatedType<? extends Annotation> findQualifierModel(final Class<?> qualifier) {
- return context.getBeanManagerImpl().getAdditionalAnnotatedTypeQualifiers().get(qualifier);
- }
-
- @Override
- public void setStartup(boolean startup) {
- this.startup = startup;
- super.setStartup(startup);
- }
-
- @Override
- public void clearCaches() {
- super.clearCaches();
- this.resolutionFailures.clear();
- }
-
- public int getCacheSize() {
- return this.resolutionFailures.size();
- }
-}
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/cdi/WebappBeanManager.java b/container/openejb-core/src/main/java/org/apache/openejb/cdi/WebappBeanManager.java
index 652344c295..8cdc657953 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/cdi/WebappBeanManager.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/cdi/WebappBeanManager.java
@@ -59,7 +59,6 @@ public class WebappBeanManager extends BeanManagerImpl {
super(ctx);
webappCtx = ctx;
deploymentBeans = super.getBeans(); // use the parent one while starting
- Reflections.set(this, "injectionResolver", new WebAppInjectionResolver(ctx));
filter = new InheritedBeanFilter(this);
}
diff --git a/container/openejb-core/src/test/java/org/apache/openejb/cdi/InjectionResolverCacheTest.java b/container/openejb-core/src/test/java/org/apache/openejb/cdi/InjectionResolverCacheTest.java
deleted file mode 100644
index 7acd5fd150..0000000000
--- a/container/openejb-core/src/test/java/org/apache/openejb/cdi/InjectionResolverCacheTest.java
+++ /dev/null
@@ -1,102 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.openejb.cdi;
-
-import org.apache.openejb.AppContext;
-import org.apache.openejb.jee.EjbJar;
-import org.apache.openejb.jee.WebApp;
-import org.apache.openejb.junit.ApplicationComposer;
-import org.apache.openejb.loader.SystemInstance;
-import org.apache.openejb.spi.ContainerSystem;
-import org.apache.openejb.testing.Classes;
-import org.apache.openejb.testing.Configuration;
-import org.apache.openejb.testing.Module;
-import org.apache.openejb.testng.PropertiesBuilder;
-import org.apache.webbeans.config.WebBeansContext;
-import org.apache.webbeans.container.BeanManagerImpl;
-import org.apache.webbeans.container.InjectionResolver;
-import org.junit.Assert;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
-import jakarta.enterprise.context.spi.CreationalContext;
-import jakarta.enterprise.inject.spi.Bean;
-import java.util.List;
-import java.util.Properties;
-
-
-/**
- * @version $Rev$ $Date$
- */
-
-@RunWith(ApplicationComposer.class)
-public class InjectionResolverCacheTest {
-
- @Module
- @Classes(cdi = true, value = { SimpleLogger.class })
- public EjbJar ejb() {
- return new EjbJar();
- }
-
- @Module
- @Classes(cdi = true)
- public WebApp web() { // we have shortcut when we have a single module so adding another one ensure we test an "ear"
- return new WebApp();
- }
-
- @Configuration
- public Properties config() {
- return new PropertiesBuilder()
- .p("openejb.cache.cdi-type-resolution-failure", "true")
- .build();
- }
-
- public static class SimpleLogger {
- public SimpleLogger() {
-
- }
-
- public void log(final String toLog) {
- if (toLog != null) {
- System.out.println(toLog);
- }
- }
- }
-
- @Test
- public void check() {
- final List<AppContext> appCtxs = SystemInstance.get().getComponent(ContainerSystem.class).getAppContexts();
-
- final WebBeansContext webBeansContext = appCtxs.get(0).getWebContexts().get(0).getWebBeansContext();
- Assert.assertTrue(webBeansContext instanceof WebappWebBeansContext);
-
- final WebappWebBeansContext webappWebBeansContext = (WebappWebBeansContext) webBeansContext;
- final BeanManagerImpl bm = webappWebBeansContext.getBeanManagerImpl();
- final InjectionResolver injectionResolver = bm.getInjectionResolver();
- Assert.assertTrue(injectionResolver instanceof WebAppInjectionResolver);
- final WebAppInjectionResolver webAppInjectionResolver = (WebAppInjectionResolver) injectionResolver;
-
- Assert.assertEquals(0, webAppInjectionResolver.getCacheSize());
-
- final Bean<?> bean = bm.resolve(bm.getBeans(SimpleLogger.class ));
- final CreationalContext<?> context = bm.createCreationalContext(bean);
- final SimpleLogger logger = (SimpleLogger) bm.getReference(bean, SimpleLogger.class, context);
-
- logger.log("Testing from web context in EAR");
- Assert.assertEquals(1, webAppInjectionResolver.getCacheSize());
- }
-}
\ No newline at end of file