openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From strub...@apache.org
Subject svn commit: r1667405 - in /openwebbeans/branches/owb_1.1.x/webbeans-impl/src: main/java/org/apache/webbeans/event/ test/java/org/apache/webbeans/test/component/event/normal/ test/java/org/apache/webbeans/test/unittests/event/component/
Date Tue, 17 Mar 2015 21:13:58 GMT
Author: struberg
Date: Tue Mar 17 21:13:58 2015
New Revision: 1667405

URL: http://svn.apache.org/r1667405
Log:
OWB-1043 fixed multiple events on same private observer methods 

We previously did setAccessible the first time but did not remember this fact.
This did lead to trying to invoke the method on the proxy each subsequent time.
Txs to VL for the bug report. 

Modified:
    openwebbeans/branches/owb_1.1.x/webbeans-impl/src/main/java/org/apache/webbeans/event/ObserverMethodImpl.java
    openwebbeans/branches/owb_1.1.x/webbeans-impl/src/test/java/org/apache/webbeans/test/component/event/normal/ComponentWithObserves1.java
    openwebbeans/branches/owb_1.1.x/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/event/component/ObserversComponentTest.java

Modified: openwebbeans/branches/owb_1.1.x/webbeans-impl/src/main/java/org/apache/webbeans/event/ObserverMethodImpl.java
URL: http://svn.apache.org/viewvc/openwebbeans/branches/owb_1.1.x/webbeans-impl/src/main/java/org/apache/webbeans/event/ObserverMethodImpl.java?rev=1667405&r1=1667404&r2=1667405&view=diff
==============================================================================
--- openwebbeans/branches/owb_1.1.x/webbeans-impl/src/main/java/org/apache/webbeans/event/ObserverMethodImpl.java
(original)
+++ openwebbeans/branches/owb_1.1.x/webbeans-impl/src/main/java/org/apache/webbeans/event/ObserverMethodImpl.java
Tue Mar 17 21:13:58 2015
@@ -108,6 +108,13 @@ public class ObserverMethodImpl<T> imple
     
     /** the transaction phase */
     private final TransactionPhase phase;
+
+    /**
+     * Whether the observer method is private.
+     * If so we need to call the observer directly on the
+     * contextual instance and not on the proxy.
+     */
+    private boolean isPrivate = false;
     
     /**Annotated method*/
     private AnnotatedMethod<T> annotatedMethod = null;
@@ -132,10 +139,9 @@ public class ObserverMethodImpl<T> imple
      */
     public ObserverMethodImpl(InjectionTargetBean<?> bean, Method observerMethod, boolean
ifExist)
     {
-        this.bean = bean;
-        this.observerMethod = observerMethod;
         this.ifExist = ifExist;
-
+        this.bean = bean;
+        setObserverMethod(observerMethod);
         Annotation[] qualifiers =
             getWebBeansContext().getAnnotationManager().getMethodFirstParameterQualifierWithGivenAnnotation(
                 observerMethod, Observes.class);
@@ -164,7 +170,7 @@ public class ObserverMethodImpl<T> imple
                                  Annotation[] qualifiers, Type observedEventType)
     {
         this.bean = bean;
-        this.observerMethod = observerMethod;
+        setObserverMethod(observerMethod);
         this.ifExist = ifExist;
         observedQualifiers = new HashSet<Annotation>(qualifiers.length);
         for (Annotation qualifier : qualifiers)
@@ -213,12 +219,6 @@ public class ObserverMethodImpl<T> imple
         ObserverParams[] obargs = null;
         try
         {
-            boolean isPrivateMethod = !observerMethod.isAccessible();
-            if (isPrivateMethod)
-            {
-                bean.getWebBeansContext().getSecurityService().doPrivilegedSetAccessible(observerMethod,
true);
-            }
-
             obargs = new ObserverParams[methodArgsMap.size()];
             obargs = methodArgsMap.toArray(obargs);
             Object[] args = new Object[obargs.length];
@@ -260,7 +260,7 @@ public class ObserverMethodImpl<T> imple
 
                 creationalContext = manager.createCreationalContext(component);
 
-                if (isPrivateMethod)
+                if (isPrivate)
                 {
                     // since private methods cannot be intercepted, we can just call them
directly
                     // so we get the contextual instance directly from the context because
we do not
@@ -577,5 +577,9 @@ public class ObserverMethodImpl<T> imple
     public void setObserverMethod(Method m)
     {
         observerMethod = m;
+
+        isPrivate = Modifier.isPrivate(observerMethod.getModifiers());
+        // we need to set the accessible flag for all private and protected methods
+        bean.getWebBeansContext().getSecurityService().doPrivilegedSetAccessible(observerMethod,
true);
     }
 }

Modified: openwebbeans/branches/owb_1.1.x/webbeans-impl/src/test/java/org/apache/webbeans/test/component/event/normal/ComponentWithObserves1.java
URL: http://svn.apache.org/viewvc/openwebbeans/branches/owb_1.1.x/webbeans-impl/src/test/java/org/apache/webbeans/test/component/event/normal/ComponentWithObserves1.java?rev=1667405&r1=1667404&r2=1667405&view=diff
==============================================================================
--- openwebbeans/branches/owb_1.1.x/webbeans-impl/src/test/java/org/apache/webbeans/test/component/event/normal/ComponentWithObserves1.java
(original)
+++ openwebbeans/branches/owb_1.1.x/webbeans-impl/src/test/java/org/apache/webbeans/test/component/event/normal/ComponentWithObserves1.java
Tue Mar 17 21:13:58 2015
@@ -32,7 +32,7 @@ public class ComponentWithObserves1
 
     private String userNameWithMember;
 
-    public void afterLoggedIn(@Observes @Any LoggedInEvent event)
+    private void afterLoggedIn(@Observes @Any LoggedInEvent event)
     {
         this.userName = event.getUserName();
     }

Modified: openwebbeans/branches/owb_1.1.x/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/event/component/ObserversComponentTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/branches/owb_1.1.x/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/event/component/ObserversComponentTest.java?rev=1667405&r1=1667404&r2=1667405&view=diff
==============================================================================
--- openwebbeans/branches/owb_1.1.x/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/event/component/ObserversComponentTest.java
(original)
+++ openwebbeans/branches/owb_1.1.x/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/event/component/ObserversComponentTest.java
Tue Mar 17 21:13:58 2015
@@ -69,15 +69,16 @@ public class ObserversComponentTest exte
         WebBeansContext.getInstance().getContextFactory().initRequestContext(null);
 
         LoggedInEvent event = new LoggedInEvent("Gurkan");
-
-        Annotation[] anns = new Annotation[1];
-        anns[0] = new AnyLiteral();        
-
-        getManager().fireEvent(event, anns);
+        getManager().fireEvent(event, new AnyLiteral());
 
         ComponentWithObserves1 instance = getManager().getInstance(component);
 
         Assert.assertEquals("Gurkan", instance.getUserName());
+
+
+        event = new LoggedInEvent("Mark");
+        getManager().fireEvent(event, new AnyLiteral());
+        Assert.assertEquals("Mark", instance.getUserName());
     }
 
     @Test



Mime
View raw message