openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject svn commit: r1790940 - in /openwebbeans/trunk/webbeans-impl/src: main/java/org/apache/webbeans/component/ test/java/org/apache/webbeans/test/producer/
Date Tue, 11 Apr 2017 08:50:57 GMT
Author: rmannibucau
Date: Tue Apr 11 08:50:57 2017
New Revision: 1790940

URL: http://svn.apache.org/viewvc?rev=1790940&view=rev
Log:
OWB-1177 ensure to check serialization on the runtime instance and not the return type (cdi
1.2 'fix')

Added:
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/producer/SerializableAtRuntimeProducerTest.java
Modified:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/AbstractProducerBean.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/ProducerFieldBean.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/ProducerMethodBean.java

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/AbstractProducerBean.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/AbstractProducerBean.java?rev=1790940&r1=1790939&r2=1790940&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/AbstractProducerBean.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/AbstractProducerBean.java
Tue Apr 11 08:50:57 2017
@@ -92,14 +92,14 @@ public class AbstractProducerBean<T> ext
     /**
      * Check passivation check.
      */
-    protected void checkScopeType(String producerName)
+    protected void checkScopeType(String producerName, Object instance)
     {
         String errorMessage = "WebBeans producer : %s" +
-                              " return type in the component implementation class : %s" +
+                              " instance in the component implementation class : %s" +
                               " with passivating scope @%s" +
                               " must be Serializable";
         getWebBeansContext().getWebBeansUtil().checkSerializableScopeType(getScope(),
-                Serializable.class.isAssignableFrom(getReturnType()), errorMessage, producerName,
getBeanClass().getName(),
+                Serializable.class.isInstance(instance), errorMessage, producerName, getBeanClass().getName(),
                 getScope().getName());
 
     }

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/ProducerFieldBean.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/ProducerFieldBean.java?rev=1790940&r1=1790939&r2=1790940&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/ProducerFieldBean.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/ProducerFieldBean.java
Tue Apr 11 08:50:57 2017
@@ -56,7 +56,7 @@ public class ProducerFieldBean<T> extend
         
         instance = super.create(creationalContext);
         checkNullInstance(instance, producerField.getName());
-        checkScopeType(producerField.getName());
+        checkScopeType(producerField.getName(), instance);
 
         return instance;
 

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/ProducerMethodBean.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/ProducerMethodBean.java?rev=1790940&r1=1790939&r2=1790940&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/ProducerMethodBean.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/ProducerMethodBean.java
Tue Apr 11 08:50:57 2017
@@ -97,7 +97,7 @@ public class ProducerMethodBean<T> exten
         checkNullInstance(instance, creatorMethod.getName());
 
         // Check scope type
-        checkScopeType(creatorMethod.getName());
+        checkScopeType(creatorMethod.getName(), instance);
         return instance;
     }
 

Added: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/producer/SerializableAtRuntimeProducerTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/producer/SerializableAtRuntimeProducerTest.java?rev=1790940&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/producer/SerializableAtRuntimeProducerTest.java
(added)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/producer/SerializableAtRuntimeProducerTest.java
Tue Apr 11 08:50:57 2017
@@ -0,0 +1,70 @@
+/*
+ * 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.webbeans.test.producer;
+
+import org.apache.webbeans.test.AbstractUnitTest;
+import org.junit.Test;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.context.SessionScoped;
+import javax.enterprise.inject.Produces;
+import java.io.Serializable;
+
+import static org.junit.Assert.assertTrue;
+
+public class SerializableAtRuntimeProducerTest extends AbstractUnitTest
+{
+    @Test
+    public void run()
+    {
+        startContainer(TheProducer.class);
+        getWebBeansContext().getContextsService().startContext(SessionScoped.class, null);
+        final NotSerializable bean = getInstance(NotSerializable.class);
+        bean.touch();
+        assertTrue(Serializable.class.isInstance(bean));
+        getWebBeansContext().getContextsService().endContext(SessionScoped.class, null);
+    }
+
+    @ApplicationScoped
+    public static class TheProducer
+    {
+        @Produces
+        @SessionScoped
+        public NotSerializable produce()
+        {
+            return new NotSerializableAndSerializable()
+            {
+                @Override
+                public void touch()
+                {
+                    // no-op
+                }
+            };
+        }
+    }
+
+    public interface NotSerializable
+    {
+        void touch();
+    }
+
+    public interface NotSerializableAndSerializable extends Serializable, NotSerializable
+    {
+    }
+}



Mime
View raw message