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

Fish 470 mdb nullpointer when customized mdb pool #5405

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
4 changes: 4 additions & 0 deletions appserver/ejb/ejb-container/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -258,5 +258,9 @@
<artifactId>opentracing-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
* only if the new code is made subject to such option by the copyright
* holder.
*/
// Portions Copyright [2016-2020] [Payara Foundation and/or its affiliates]
// Portions Copyright [2016-2021] [Payara Foundation and/or its affiliates]

package com.sun.ejb.containers;

Expand Down Expand Up @@ -1785,6 +1785,11 @@ protected Object _constructEJBInstance() throws Exception {
private void createEjbInterceptors(EJBContextImpl context,
JCDIService.JCDIInjectionContext<?> ejbInterceptorsJCDIInjectionContext) throws Exception {
Object[] interceptorInstances;
//sanitizing the null reference of interceptorManager
if (interceptorManager == null) {
_logger.severe("The reference for interceptorManager is not available, this is an un-sync state of the container");
return;
}

if (isJCDIEnabled()) {
Class[] interceptorClasses = interceptorManager.getInterceptorClasses();
Expand Down Expand Up @@ -2058,7 +2063,11 @@ public void preInvoke(EjbInvocation inv) {

public boolean intercept(CallbackType eventType, EJBContextImpl ctx)
throws Throwable {

//sanitizing the null reference of interceptorManager
if (interceptorManager == null) {
_logger.severe("The reference for interceptorManager is not available, this is an un-sync state of the container");
return false;
}
return interceptorManager.intercept(eventType, ctx);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) [2021] Payara Foundation and/or its affiliates. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can
* obtain a copy of the License at
* https://github.com/payara/Payara/blob/master/LICENSE.txt
* See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at glassfish/legal/LICENSE.txt.
*
* GPL Classpath Exception:
* The Payara Foundation designates this particular file as subject to the "Classpath"
* exception as provided by the Payara Foundation in the GPL Version 2 section of the License
* file that accompanied this code.
*
* Modifications:
* If applicable, add the following below the License Header, with the fields
* enclosed by brackets [] replaced by your own identifying information:
* "Portions Copyright [year] [name of copyright owner]"
*
* Contributor(s):
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
package com.sun.ejb.containers;

import com.sun.enterprise.deployment.LifecycleCallbackDescriptor;
import junit.framework.TestCase;
breakponchito marked this conversation as resolved.
Show resolved Hide resolved
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;

import static org.mockito.Mockito.*;

@RunWith(MockitoJUnitRunner.class)
public class BaseContainerTest extends TestCase {

@Mock
private EJBContextImpl ejbContextImpl;

@Mock
private BaseContainer baseContainer;

@Test
public void createEmptyContextAndInterceptorsWithoutNullPointerExceptionTest() throws Exception {
boolean thrownExceptionFlag = false;

doCallRealMethod().when(baseContainer).createEmptyContextAndInterceptors(ejbContextImpl);

try {
baseContainer.createEmptyContextAndInterceptors(ejbContextImpl);
} catch(NullPointerException e) {
thrownExceptionFlag = true;
}
assertFalse(thrownExceptionFlag);
verify(baseContainer, times(1)).createEmptyContextAndInterceptors(ejbContextImpl);
}

@Test
public void interceptMethodWithoutNullPointerExceptionTest() throws Throwable{
boolean thrownExceptionFlag = false;

doCallRealMethod().when(baseContainer).intercept(LifecycleCallbackDescriptor.CallbackType.AROUND_CONSTRUCT,
ejbContextImpl);
try {
baseContainer.intercept(LifecycleCallbackDescriptor.CallbackType.AROUND_CONSTRUCT, ejbContextImpl);
} catch(NullPointerException e) {
thrownExceptionFlag = true;
}

assertFalse(thrownExceptionFlag);
verify(baseContainer, times(1)).intercept(LifecycleCallbackDescriptor.CallbackType.AROUND_CONSTRUCT,
ejbContextImpl);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
* only if the new code is made subject to such option by the copyright
* holder.
*/
// Portions Copyright [2017-2019] [Payara Foundation and/or its affiliates]
// Portions Copyright [2017-2021] [Payara Foundation and/or its affiliates]
package org.glassfish.ejb.mdb;

import com.sun.appserv.connectors.internal.api.ConnectorRuntime;
Expand Down Expand Up @@ -799,7 +799,11 @@ private MessageBeanContextImpl createMessageDrivenEJB() throws CreateException {

// Call ejbCreate OR @PostConstruct on the bean.
intercept(POST_CONSTRUCT, context);

//sanitizing the null reference of ejbProbeNotifier and returning null
if(ejbProbeNotifier == null) {
_logger.severe("The reference for ejbProbeNotifier is not available, this is an un-sync state of the container");
return null;
}
ejbProbeNotifier.ejbBeanCreatedEvent(getContainerId(),
containerInfo.appName, containerInfo.modName,
containerInfo.ejbName);
Expand Down
4 changes: 4 additions & 0 deletions appserver/web/weld-integration/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -216,5 +216,9 @@
<artifactId>concurrent-connector</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
* only if the new code is made subject to such option by the copyright
* holder.
*/
// Portions Copyright [2016-2019] [Payara Foundation and/or its affiliates]
// Portions Copyright [2016-2021] [Payara Foundation and/or its affiliates]

package org.glassfish.weld.services;

Expand Down Expand Up @@ -213,7 +213,12 @@ private <T> JCDIInjectionContext<T> _createJCDIInjectionContext(EjbDescriptor ej

WeldBootstrap bootstrap = weldDeployer.getBootstrapForApp(ejb.getEjbBundleDescriptor().getApplication());
WeldManager weldManager = bootstrap.getManager(bda);

//sanitizing the null reference of weldManager and returning null
//when calling _createJCDIInjectionContext
if(weldManager == null) {
logger.severe("The reference for weldManager is not available, this is an un-sync state of the container");
return null;
}
org.jboss.weld.ejb.spi.EjbDescriptor<T> ejbDesc = weldManager.getEjbDescriptor(ejb.getName());

// get or create the ejb's creational context
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
* only if the new code is made subject to such option by the copyright
* holder.
*/

// Portions Copyright [2021] [Payara Foundation and/or its affiliates]
package org.glassfish.weld;

import org.jboss.weld.bootstrap.api.SingletonProvider;
Expand All @@ -56,6 +56,8 @@ public void testAll() throws Exception {

Field instanceField = SingletonProvider.class.getDeclaredField("INSTANCE");
instanceField.setAccessible(true);
//nullifyng the internal reference of the SingletonProvider to not bleed across tests
instanceField.set(aclSingletonProvider, null);
assertNull(instanceField.get(aclSingletonProvider));

WeldActivator weldActivator = new WeldActivator();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) [2021] Payara Foundation and/or its affiliates. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can
* obtain a copy of the License at
* https://github.com/payara/Payara/blob/master/LICENSE.txt
* See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at glassfish/legal/LICENSE.txt.
*
* GPL Classpath Exception:
* The Payara Foundation designates this particular file as subject to the "Classpath"
* exception as provided by the Payara Foundation in the GPL Version 2 section of the License
* file that accompanied this code.
*
* Modifications:
* If applicable, add the following below the License Header, with the fields
* enclosed by brackets [] replaced by your own identifying information:
* "Portions Copyright [year] [name of copyright owner]"
*
* Contributor(s):
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
package org.glassfish.weld.services;

import com.sun.enterprise.deployment.Application;
import com.sun.enterprise.deployment.BundleDescriptor;
import com.sun.enterprise.deployment.EjbBundleDescriptor;
import com.sun.enterprise.deployment.EjbDescriptor;
import junit.framework.TestCase;
import org.glassfish.deployment.common.ModuleDescriptor;
import org.glassfish.weld.WeldDeployer;
import org.jboss.weld.bootstrap.WeldBootstrap;
import org.jboss.weld.bootstrap.spi.BeanDeploymentArchive;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;

import java.util.Collection;
import java.util.Collections;
import java.util.Map;

import static org.mockito.Mockito.*;

@RunWith(MockitoJUnitRunner.class)
public class JCDIServiceImplTest extends TestCase {

@Mock
private EjbDescriptor ejbDescriptor;

@Mock
private EjbBundleDescriptor ejbBundleDescriptor;

@Mock
private ModuleDescriptor moduleDescriptor;

@Mock
private BundleDescriptor bundleDescriptor;

@Mock
private WeldDeployer weldDeployer;

@Mock
private BeanDeploymentArchive beanDeploymentArchive;

@Mock
private WeldBootstrap bootstrap;

@Mock
private Application application;

@InjectMocks
private JCDIServiceImpl jcdiServiceImpl = new JCDIServiceImpl();

@Test
public void createJCDIInjectionContextWithoutNullPointerException() {
Map<Class<?>, Object> ejbInfo = Collections.emptyMap();
Collection<String> emptyListNames = Collections.emptyList();
Collection<BeanDeploymentArchive> emptyListOfArchives = Collections.emptyList();
when(ejbDescriptor.getEjbBundleDescriptor()).thenReturn(ejbBundleDescriptor);
when(ejbBundleDescriptor.getApplication()).thenReturn(application);
when(ejbBundleDescriptor.getModuleDescriptor()).thenReturn(moduleDescriptor);
when(moduleDescriptor.getDescriptor()).thenReturn(bundleDescriptor);
when(ejbDescriptor.getEjbClassName()).thenReturn("EjbName");
when(weldDeployer.getBeanDeploymentArchiveForBundle(bundleDescriptor)).thenReturn(beanDeploymentArchive);
when(weldDeployer.getBootstrapForApp(application)).thenReturn(bootstrap);
when(beanDeploymentArchive.getBeanClasses()).thenReturn(emptyListNames);
when(beanDeploymentArchive.getBeanDeploymentArchives()).thenReturn(emptyListOfArchives);

Object obj = jcdiServiceImpl.createJCDIInjectionContext(ejbDescriptor, ejbInfo);

assertNull(obj);
verify(ejbDescriptor, times(2)).getEjbBundleDescriptor();
verify(ejbBundleDescriptor, times(1)).getModuleDescriptor();
verify(moduleDescriptor, times(1)).getDescriptor();
verify(weldDeployer, times(1)).getBeanDeploymentArchiveForBundle(bundleDescriptor);
verify(beanDeploymentArchive, times(1)).getBeanClasses();
verify(beanDeploymentArchive, times(1)).getBeanDeploymentArchives();
verify(ejbBundleDescriptor, times(1)).getApplication();
verify(weldDeployer, times(1)).getBootstrapForApp(application);
verify(bootstrap, times(1)).getManager(beanDeploymentArchive);
}
}