openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From strub...@apache.org
Subject svn commit: r1600999 - in /openwebbeans/trunk/webbeans-impl/src: main/java/org/apache/webbeans/util/ test/java/org/apache/webbeans/test/injection/generics/
Date Fri, 06 Jun 2014 20:28:55 GMT
Author: struberg
Date: Fri Jun  6 20:28:54 2014
New Revision: 1600999

URL: http://svn.apache.org/r1600999
Log:
OWB-968 fix infinite loop in Generics handling of Enums

happens because is illegally defined as 
 Enum<E extends Enum<E>>
which actually contradicts the Java lang spec...

Added:
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/injection/generics/BazEnum.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/injection/generics/BazEnumProducer.java
Modified:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/ClassUtil.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/GenericsUtil.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/injection/generics/GenericsTest.java

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/ClassUtil.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/ClassUtil.java?rev=1600999&r1=1600998&r2=1600999&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/ClassUtil.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/ClassUtil.java
Fri Jun  6 20:28:54 2014
@@ -61,6 +61,8 @@ public final class ClassUtil
         PRIMITIVE_TO_WRAPPERS_MAP.put(Void.TYPE,Void.class);
     }
 
+    public static final Type[] NO_TYPES = new Type[0];
+
     /*
      * Private constructor
      */
@@ -726,7 +728,7 @@ public final class ClassUtil
         }
         else
         {
-            return new Type[0];
+            return NO_TYPES;
         }
     }
 

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/GenericsUtil.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/GenericsUtil.java?rev=1600999&r1=1600998&r2=1600999&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/GenericsUtil.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/GenericsUtil.java
Fri Jun  6 20:28:54 2014
@@ -462,7 +462,20 @@ public final class GenericsUtil
         else if (type instanceof ParameterizedType)
         {
             ParameterizedType parameterizedType = (ParameterizedType)type;
-            Type[] resolvedTypeArguments = resolveTypes(parameterizedType.getActualTypeArguments(),
actualType);
+
+            Type[] resolvedTypeArguments;
+            if (Enum.class.equals(parameterizedType.getRawType()))
+            {
+                // Enums derive from themselves, which would create an infinite loop
+                // we directly escape the loop if we detect this.
+                resolvedTypeArguments = new Type[]{new OwbWildcardTypeImpl(new Type[]{Enum.class},
ClassUtil.NO_TYPES)};
+            }
+            else
+            {
+                resolvedTypeArguments = resolveTypes(parameterizedType.getActualTypeArguments(),
actualType);
+
+            }
+
             return new OwbParametrizedTypeImpl(parameterizedType.getOwnerType(), parameterizedType.getRawType(),
resolvedTypeArguments);
         }
         else if (type instanceof TypeVariable)

Added: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/injection/generics/BazEnum.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/injection/generics/BazEnum.java?rev=1600999&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/injection/generics/BazEnum.java
(added)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/injection/generics/BazEnum.java
Fri Jun  6 20:28:54 2014
@@ -0,0 +1,27 @@
+/*
+ * 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.injection.generics;
+
+/**
+ * Scanning enums did blow up our GenericsUtil with an infinite loop...
+ */
+public enum BazEnum
+{
+    YES, NO;
+}

Added: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/injection/generics/BazEnumProducer.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/injection/generics/BazEnumProducer.java?rev=1600999&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/injection/generics/BazEnumProducer.java
(added)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/injection/generics/BazEnumProducer.java
Fri Jun  6 20:28:54 2014
@@ -0,0 +1,33 @@
+/*
+ * 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.injection.generics;
+
+import javax.enterprise.inject.Produces;
+
+/**
+ * Scanning enums did blow up our GenericsUtil with an infinite loop...
+ */
+public class BazEnumProducer
+{
+    @Produces
+    public BazEnum createBazEnum()
+    {
+        return BazEnum.YES;
+    }
+}

Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/injection/generics/GenericsTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/injection/generics/GenericsTest.java?rev=1600999&r1=1600998&r2=1600999&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/injection/generics/GenericsTest.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/injection/generics/GenericsTest.java
Fri Jun  6 20:28:54 2014
@@ -30,8 +30,8 @@ import javax.enterprise.inject.spi.Injec
 import javax.enterprise.inject.spi.ObserverMethod;
 import javax.enterprise.util.TypeLiteral;
 
+import junit.framework.Assert;
 import org.apache.webbeans.test.AbstractUnitTest;
-import org.junit.Ignore;
 import org.junit.Test;
 
 
@@ -112,4 +112,19 @@ public class GenericsTest extends Abstra
         assertNotNull(foo.getABazEvent());
         assertEquals((String) foo.getAObserverInjectionPoint(), "a produced String");
     }
+
+    @Test
+    public void testEnum() throws Exception
+    {
+        startContainer(BazEnum.class);
+    }
+
+    @Test
+    public void testEnumProducer() throws Exception
+    {
+        startContainer(BazEnumProducer.class);
+        BazEnum bazEnum = getInstance(BazEnum.class);
+        Assert.assertNotNull(bazEnum);
+        Assert.assertEquals(BazEnum.YES, bazEnum);
+    }
 }



Mime
View raw message