From fffa1fa021f3cc2e1b2a7c2d619e79e6d84ec72a Mon Sep 17 00:00:00 2001 From: Clint Popetz Date: Tue, 26 Oct 2010 14:45:11 -0500 Subject: [PATCH] WELD-743 --- .../weld/injection/WeldInjectionPoint.java | 5 +- .../NonContextual.java | 28 +++++++++ .../SerializationTest.java | 61 +++++++++++++++++++ 3 files changed, 92 insertions(+), 2 deletions(-) create mode 100644 tests-arquillian/src/test/java/org/jboss/weld/tests/serializationNonContextual/NonContextual.java create mode 100644 tests-arquillian/src/test/java/org/jboss/weld/tests/serializationNonContextual/SerializationTest.java diff --git a/impl/src/main/java/org/jboss/weld/injection/WeldInjectionPoint.java b/impl/src/main/java/org/jboss/weld/injection/WeldInjectionPoint.java index fd363e5bda6..8989620906b 100644 --- a/impl/src/main/java/org/jboss/weld/injection/WeldInjectionPoint.java +++ b/impl/src/main/java/org/jboss/weld/injection/WeldInjectionPoint.java @@ -40,13 +40,14 @@ static abstract class WeldInjectionPointSerializationProxy implements Seri public WeldInjectionPointSerializationProxy(WeldInjectionPoint injectionPoint) { - this.declaringBeanId = Container.instance().services().get(ContextualStore.class).putIfAbsent(injectionPoint.getBean()); + this.declaringBeanId = + injectionPoint.getBean() == null ? null : Container.instance().services().get(ContextualStore.class).putIfAbsent(injectionPoint.getBean()); this.declaringClass = injectionPoint.getDeclaringType().getJavaClass(); } protected Bean getDeclaringBean() { - return Container.instance().services().get(ContextualStore.class)., T>getContextual(declaringBeanId); + return declaringBeanId == null ? null : Container.instance().services().get(ContextualStore.class)., T>getContextual(declaringBeanId); } protected WeldClass getDeclaringWeldClass() diff --git a/tests-arquillian/src/test/java/org/jboss/weld/tests/serializationNonContextual/NonContextual.java b/tests-arquillian/src/test/java/org/jboss/weld/tests/serializationNonContextual/NonContextual.java new file mode 100644 index 00000000000..abf4c382e59 --- /dev/null +++ b/tests-arquillian/src/test/java/org/jboss/weld/tests/serializationNonContextual/NonContextual.java @@ -0,0 +1,28 @@ +/* + * JBoss, Home of Professional Open Source + * Copyright 2010, Red Hat, Inc., and individual contributors + * by the @authors tag. See the copyright.txt in the distribution for a + * full listing of individual contributors. + * + * Licensed 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.jboss.weld.tests.serialization.noncontextual; + +import java.io.Serializable; +import javax.enterprise.event.Event; +import javax.inject.Inject; + +public class NonContextual implements Serializable +{ + + @Inject Event stringEvent; + +} diff --git a/tests-arquillian/src/test/java/org/jboss/weld/tests/serializationNonContextual/SerializationTest.java b/tests-arquillian/src/test/java/org/jboss/weld/tests/serializationNonContextual/SerializationTest.java new file mode 100644 index 00000000000..1a6748d91ca --- /dev/null +++ b/tests-arquillian/src/test/java/org/jboss/weld/tests/serializationNonContextual/SerializationTest.java @@ -0,0 +1,61 @@ +/* + * JBoss, Home of Professional Open Source + * Copyright 2010, Red Hat, Inc., and individual contributors + * by the @authors tag. See the copyright.txt in the distribution for a + * full listing of individual contributors. + * + * Licensed 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.jboss.weld.tests.serialization.noncontextual; + +import static org.junit.Assert.fail; +import javax.inject.Inject; + +import java.io.Serializable; +import java.io.*; + +import javax.enterprise.inject.spi.BeanManager; +import javax.enterprise.context.spi.Contextual; +import org.jboss.arquillian.api.Deployment; +import org.jboss.arquillian.junit.Arquillian; +import org.jboss.shrinkwrap.api.Archive; +import org.jboss.shrinkwrap.api.BeanArchive; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; + +@RunWith(Arquillian.class) +public class SerializationTest +{ + + @Inject BeanManager beanManager; + + @Deployment + public static Archive deploy() + { + return ShrinkWrap.create(BeanArchive.class).addPackage(SerializationTest.class.getPackage()); + } + + /* + * description = + * "http://lists.jboss.org/pipermail/weld-dev/2010-February/002265.html" + */ + @Test + public void testSerializationOfEventInNonContextual() throws Exception + { + + NonContextual instance = new NonContextual(); + beanManager.createInjectionTarget(beanManager.createAnnotatedType(NonContextual.class)).inject( + instance, beanManager.createCreationalContext((Contextual)null)); + new ObjectOutputStream(new ByteArrayOutputStream()).writeObject(instance); + } +}