Path: blob/master/test/jdk/java/beans/beancontext/Test4328406.java
41149 views
/*1* Copyright (c) 2002, 2007, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 432840626* @summary Tests NPE while removing a BeanContextServices27* @author Mark Davidson28*/2930import java.beans.beancontext.BeanContextChild;31import java.beans.beancontext.BeanContextChildSupport;32import java.beans.beancontext.BeanContextServiceProvider;33import java.beans.beancontext.BeanContextServices;34import java.beans.beancontext.BeanContextServicesSupport;35import java.util.Iterator;3637public class Test4328406 {38public static void main(String[] args) {39for (int i = 0; i < 10; i++) {40BeanContextServices container = new BeanContextServicesSupport();41BeanContextChild ms1 = new MyService1();42BeanContextServices ms2 = new MyService2();43BeanContextChild mb = new MyBean();4445container.add(ms1);46container.add(ms2);47ms2.add(mb);4849// exception thrown here50container.remove(ms2);51}52}53}5455class MyService1 extends BeanContextChildSupport implements BeanContextServiceProvider {56protected void initializeBeanContextResources() {57super.initializeBeanContextResources();5859BeanContextServices bcs = (BeanContextServices) getBeanContext();60bcs.addService(this.getClass(), this);61}6263public Object getService(BeanContextServices bcs, Object requestor, Class serviceClass, Object serviceSelector) {64return this;65}6667public void releaseService(BeanContextServices bcs, Object requestor, Object68service) {69}7071public Iterator getCurrentServiceSelectors(BeanContextServices bcs, Class serviceClass) {72return null;73}74}7576class MyService2 extends BeanContextServicesSupport implements BeanContextServiceProvider {77protected void initializeBeanContextResources() {78super.initializeBeanContextResources();7980BeanContextServicesSupport bcs = (BeanContextServicesSupport) getBeanContext();81try {82bcs.getService(this, this, MyService1.class, null, this);83}84catch (Exception exception) {85exception.printStackTrace();86}87bcs.addService(this.getClass(), this);88}8990protected void releaseBeanContextResources() {91super.releaseBeanContextResources();9293BeanContextServices bcs = (BeanContextServices) getBeanContext();94bcs.revokeService(this.getClass(), this, true);95}9697public Object getService(BeanContextServices bcs, Object requestor, Class serviceClass, Object serviceSelector) {98return this;99}100101public void releaseService(BeanContextServices bcs, Object requestor, Object service) {102}103104public Iterator getCurrentServiceSelectors(BeanContextServices bcs, Class serviceClass) {105return null;106}107}108109class MyBean extends BeanContextChildSupport {110protected void initializeBeanContextResources() {111super.initializeBeanContextResources();112113BeanContextServices bcs = (BeanContextServices) getBeanContext();114try {115bcs.getService(this, this, MyService1.class, null, this);116}117catch (Exception exception) {118exception.printStackTrace();119}120try {121bcs.getService(this, this, MyService2.class, null, this);122}123catch (Exception exception) {124exception.printStackTrace();125}126}127}128129130