felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From b..@apache.org
Subject svn commit: r1643495 - in /felix/trunk/framework/src: main/java/org/apache/felix/framework/BundleWiringImpl.java main/java/org/apache/felix/framework/WovenClassImpl.java test/java/org/apache/felix/framework/BundleWiringImplTest.java
Date Sat, 06 Dec 2014 05:52:46 GMT
Author: bob
Date: Sat Dec  6 05:52:46 2014
New Revision: 1643495

URL: http://svn.apache.org/r1643495
Log:
FELIX-4724 Separate transform state behavior (bytes and import lists made immutable) from
define behavior (set classname).

Modified:
    felix/trunk/framework/src/main/java/org/apache/felix/framework/BundleWiringImpl.java
    felix/trunk/framework/src/main/java/org/apache/felix/framework/WovenClassImpl.java
    felix/trunk/framework/src/test/java/org/apache/felix/framework/BundleWiringImplTest.java

Modified: felix/trunk/framework/src/main/java/org/apache/felix/framework/BundleWiringImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/framework/src/main/java/org/apache/felix/framework/BundleWiringImpl.java?rev=1643495&r1=1643494&r2=1643495&view=diff
==============================================================================
--- felix/trunk/framework/src/main/java/org/apache/felix/framework/BundleWiringImpl.java (original)
+++ felix/trunk/framework/src/main/java/org/apache/felix/framework/BundleWiringImpl.java Sat
Dec  6 05:52:46 2014
@@ -2094,9 +2094,11 @@ public class BundleWiringImpl implements
                         } 
                         catch (Error e)
                         {
-                          wci.setState(WovenClass.TRANSFORMING_FAILED);
-                          callWovenClassListeners(felix, wovenClassListeners, wci);
-                          throw e;
+                            // Mark the woven class as incomplete.
+                            wci.complete(null, null, null);
+                            wci.setState(WovenClass.TRANSFORMING_FAILED);
+                            callWovenClassListeners(felix, wovenClassListeners, wci);
+                            throw e;
                         }
                     }
                     // Before we actually attempt to define the class, grab
@@ -2139,6 +2141,7 @@ public class BundleWiringImpl implements
                             wci.setState(WovenClass.DEFINE_FAILED);
                             callWovenClassListeners(felix, wovenClassListeners, wci);
                         }
+                        throw e;
                     }
 
                     // Perform deferred activation without holding the class loader lock,
@@ -2353,6 +2356,7 @@ public class BundleWiringImpl implements
                         }
                         if(wci != null)
                         {
+                            wci.completeDefine(clazz);
                             wci.setState(WovenClass.DEFINED);
                             callWovenClassListeners(felix, wovenClassListeners, wci);
                         }
@@ -2368,15 +2372,6 @@ public class BundleWiringImpl implements
             }
             finally
             {
-                // If we have a woven class, mark it as complete.
-                // Not exactly clear how we should deal with the
-                // case where the weaving didn't happen because
-                // someone else beat us in defining the class.
-                if (wci != null)
-                {
-                    wci.complete(clazz, bytes, wci.getDynamicImportsInternal());
-                }
-
                 synchronized (lock)
                 {
                     m_classLocks.remove(name);
@@ -2420,8 +2415,6 @@ public class BundleWiringImpl implements
                                     sr.getBundle(),
                                     th);
 
-                            // Mark the woven class as incomplete.
-                            wci.complete(null, null, null);
                             // Throw class format exception per spec.
                             Error error = new ClassFormatError("Weaving hook failed.");
                             error.initCause(th);

Modified: felix/trunk/framework/src/main/java/org/apache/felix/framework/WovenClassImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/framework/src/main/java/org/apache/felix/framework/WovenClassImpl.java?rev=1643495&r1=1643494&r2=1643495&view=diff
==============================================================================
--- felix/trunk/framework/src/main/java/org/apache/felix/framework/WovenClassImpl.java (original)
+++ felix/trunk/framework/src/main/java/org/apache/felix/framework/WovenClassImpl.java Sat
Dec  6 05:52:46 2014
@@ -54,11 +54,21 @@ class WovenClassImpl implements WovenCla
     synchronized void complete(Class definedClass, byte[] bytes,
             List<String> imports)
     {
-        m_definedClass = definedClass;
+        completeDefine(definedClass);
         m_bytes = (bytes == null) ? m_bytes : bytes;
+        completeImports(imports);
+    }
+    
+    synchronized void completeImports(List<String> imports)
+    {
         m_imports = (imports == null) ? ImmutableList.newInstance(m_imports)
                 : ImmutableList.newInstance(imports);
     }
+    
+    synchronized void completeDefine(Class definedClass)
+    {
+        m_definedClass = definedClass;
+    }
 
     public synchronized byte[] getBytes()
     {
@@ -85,7 +95,7 @@ class WovenClassImpl implements WovenCla
             sm.checkPermission(new AdminPermission(m_wiring.getBundle(),
                     AdminPermission.WEAVE));
         }
-        if (m_isComplete)
+        if (m_state >= TRANSFORMED)
         {
             throw new IllegalStateException(
                     "Cannot change bytes after class weaving is completed.");
@@ -403,6 +413,10 @@ class WovenClassImpl implements WovenCla
         {
             m_isComplete = true;
         }
+        if(state == TRANSFORMED)
+        {
+            completeImports(null);
+        }
         m_state = state;
     }
 

Modified: felix/trunk/framework/src/test/java/org/apache/felix/framework/BundleWiringImplTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/framework/src/test/java/org/apache/felix/framework/BundleWiringImplTest.java?rev=1643495&r1=1643494&r2=1643495&view=diff
==============================================================================
--- felix/trunk/framework/src/test/java/org/apache/felix/framework/BundleWiringImplTest.java
(original)
+++ felix/trunk/framework/src/test/java/org/apache/felix/framework/BundleWiringImplTest.java
Sat Dec  6 05:52:46 2014
@@ -350,9 +350,10 @@ public class BundleWiringImplTest
         {
 
             bundleClassLoader.findClass(TestClass.class.getName());
-        } catch (ClassNotFoundException e)
+            fail("Class should throw exception");
+        } catch (Throwable e)
         {
-            fail("Class should not throw exception");
+            
         }
         assertEquals("There should be 2 state changes fired by the weaving", 2,
                 dummyWovenClassListener.stateList.size());



Mime
View raw message