openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject svn commit: r1847620 - in /openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans: annotation/AnnotationManager.java component/creation/BeanAttributesBuilder.java portable/AbstractAnnotated.java
Date Wed, 28 Nov 2018 08:07:09 GMT
Author: rmannibucau
Date: Wed Nov 28 08:07:09 2018
New Revision: 1847620

URL: http://svn.apache.org/viewvc?rev=1847620&view=rev
Log:
OWB-1271 wrapping repeatableMethodCache values in Optional to reduce the number of NPE

Modified:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/annotation/AnnotationManager.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/BeanAttributesBuilder.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/AbstractAnnotated.java

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/annotation/AnnotationManager.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/annotation/AnnotationManager.java?rev=1847620&r1=1847619&r2=1847620&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/annotation/AnnotationManager.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/annotation/AnnotationManager.java
Wed Nov 28 08:07:09 2018
@@ -59,6 +59,7 @@ import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
+import java.util.Optional;
 import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.CopyOnWriteArraySet;
@@ -74,7 +75,7 @@ public final class AnnotationManager
         new ConcurrentHashMap<>();
 
     private CopyOnWriteArraySet<Class<?>> repeatableMethodCheckedTypes = new
CopyOnWriteArraySet<>();
-    private Map<Class<?>, Method> repeatableMethodCache = new ConcurrentHashMap<>();
+    private Map<Class<?>, Optional<Method>> repeatableMethodCache = new
ConcurrentHashMap<>();
 
     private final BeanManagerImpl beanManagerImpl;
     private final WebBeansContext webBeansContext;
@@ -940,17 +941,17 @@ public final class AnnotationManager
         repeatableMethodCache.clear();
     }
 
-    public Method getRepeatableMethod(Class<?> type)
+    public Optional<Method> getRepeatableMethod(Class<?> type)
     {
         if (repeatableMethodCheckedTypes.contains(type))
         {
             return repeatableMethodCache.get(type);
         }
 
-        Method method = resolveRepeatableMethod(type);
+        Optional<Method> method = Optional.ofNullable(resolveRepeatableMethod(type));
         
         repeatableMethodCheckedTypes.add(type);
-        repeatableMethodCache.put(type, method);
+        repeatableMethodCache.put(type, method); // don't put null here!
         
         return method;
     }

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/BeanAttributesBuilder.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/BeanAttributesBuilder.java?rev=1847620&r1=1847619&r2=1847620&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/BeanAttributesBuilder.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/creation/BeanAttributesBuilder.java
Wed Nov 28 08:07:09 2018
@@ -303,7 +303,7 @@ public abstract class BeanAttributesBuil
     {
         return AbstractAnnotated.class.isInstance(annotated) ?
                 AbstractAnnotated.class.cast(annotated).getRepeatables().contains(annotation.annotationType())
:
-                webBeansContext.getAnnotationManager().getRepeatableMethod(annotation.annotationType())
!= null;
+                webBeansContext.getAnnotationManager().getRepeatableMethod(annotation.annotationType()).isPresent();
     }
 
     /**

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/AbstractAnnotated.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/AbstractAnnotated.java?rev=1847620&r1=1847619&r2=1847620&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/AbstractAnnotated.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/AbstractAnnotated.java
Wed Nov 28 08:07:09 2018
@@ -26,6 +26,7 @@ import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Objects;
+import java.util.Optional;
 import java.util.Set;
 import java.util.stream.Stream;
 
@@ -98,12 +99,13 @@ public abstract class AbstractAnnotated
                     Class<?> type = a.annotationType();
                     try
                     {
-                        Method repeatableMethod = webBeansContext.getAnnotationManager().getRepeatableMethod(type);
-                        if (repeatableMethod == null)
+                        Optional<Method> repeatableMethod =
+                                webBeansContext.getAnnotationManager().getRepeatableMethod(type);
+                        if (!repeatableMethod.isPresent())
                         {
                             return null;
                         }
-                        return (Annotation[]) repeatableMethod.invoke(a);
+                        return (Annotation[]) repeatableMethod.orElseThrow(IllegalStateException::new).invoke(a);
                     }
                     catch (Exception e)
                     {



Mime
View raw message