You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by we...@apache.org on 2010/09/14 18:20:30 UTC

svn commit: r996973 - /myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/loaders/java/ThrowawayClassloader.java

Author: werpu
Date: Tue Sep 14 16:20:30 2010
New Revision: 996973

URL: http://svn.apache.org/viewvc?rev=996973&view=rev
Log:
https://issues.apache.org/jira/browse/EXTSCRIPT-143
reverted the compiled check because the java compiler automatically compiles dependencies with it which might not have changed, and we are getting classcast exceptions, it is better simply to check for refresh requested instead for now .. but in the end it might be preferrable to check in the refresh part for tainted (backwards referencing) and compiled (forward referencing)


Modified:
    myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/loaders/java/ThrowawayClassloader.java

Modified: myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/loaders/java/ThrowawayClassloader.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/loaders/java/ThrowawayClassloader.java?rev=996973&r1=996972&r2=996973&view=diff
==============================================================================
--- myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/loaders/java/ThrowawayClassloader.java (original)
+++ myfaces/extensions/scripting/trunk/extscript-core-root/extscript-core/src/main/java/org/apache/myfaces/extensions/scripting/loaders/java/ThrowawayClassloader.java Tue Sep 14 16:20:30 2010
@@ -38,7 +38,7 @@ import static java.util.logging.Level.*;
  * we move the throw away mechanism into our classloader for cleaner code coverage
  * the idea is to throw away classloaders on demand if a class is reloaded
  * we throw it away at two stages
- * 
+ * <p/>
  * first at call stage from outside if we manually load a class
  * and secondly internally if a class is reloaded by the system
  * or if something calls loadClass directly
@@ -69,7 +69,6 @@ public class ThrowawayClassloader extend
     ThrowawayClassloader() {
     }
 
- 
 
     @Override
     public InputStream getResourceAsStream(String name) {
@@ -91,14 +90,13 @@ public class ThrowawayClassloader extend
      */
     public Class<?> loadClass(String className) throws ClassNotFoundException {
         //check if our class exists in the tempDir
+        //we have to register ourselves temporarily because the trhow away classloader
+        //can be called implicitely
 
-      
-
-        //TODO handle the $ case which should not revert to a new classloader
 
         File target = WeavingContext.getConfiguration().resolveClassFile(className);
         if (target.exists()) {
-                       
+
             _logger.log(Level.FINE, "[EXT-SCRIPTING] target {0} exists", className);
 
             ClassResource data = WeavingContext.getFileChangedDaemon().getClassMap().get(className);
@@ -106,7 +104,11 @@ public class ThrowawayClassloader extend
             //this check must be present because
             //the vm recycles old classloaders to load classes a anew
             //if we dont do it we get an exception
-            if(data != null && !data.isRecompiled()) {
+            //we cannot check here for the file timestamps because if we have import dependencies
+            //it can happen that the compiler refreshes the forward dependend file as well
+            //and then we reload the class in one file but reference it from an artifact
+            //in another, it is better to check for the taint state instead
+            if (data != null && !data.getRefreshAttribute().requiresRefresh()) {
 
                 return data.getAClass();
             }
@@ -139,7 +141,7 @@ public class ThrowawayClassloader extend
                     }
                 }
             }
-            
+
 
             if (data != null) {
                 File sourceFile = data.getFile();
@@ -150,7 +152,7 @@ public class ThrowawayClassloader extend
 
                 //sometimes the classloader is recycled between requests due to being bound to the old class, we have to open a new classloader here just for the sake
                 //to avoid conflicts
-                retVal = (new ThrowawayClassloader(getParent() ,_scriptingEngine, _engineExtension)).defineClass(className, fileContent, 0, fileLength);
+                retVal = (new ThrowawayClassloader(getParent(), _scriptingEngine, _engineExtension)).defineClass(className, fileContent, 0, fileLength);
                 data.setAClass(retVal);
                 data.getRefreshAttribute().executedRefresh();
                 data.executeLastLoaded();
@@ -166,6 +168,8 @@ public class ThrowawayClassloader extend
         return super.loadClass(className);
     }
 
+
+
     private Class<?> storeReloadableDefinitions(String className, int fileLength, byte[] fileContent) {
         Class retVal;
         retVal = super.defineClass(className, fileContent, 0, fileLength);
@@ -175,7 +179,7 @@ public class ThrowawayClassloader extend
         //store the filename
         String separator = FileUtils.getFileSeparatorForRegex();
         String fileName = className.replaceAll("\\.", separator);
-        fileName = (fileName.indexOf("$") != -1)?  fileName.substring(0,fileName.indexOf("$")): fileName;
+        fileName = (fileName.indexOf("$") != -1) ? fileName.substring(0, fileName.indexOf("$")) : fileName;
 
         fileName = fileName.replaceAll("\\.", separator) + getStandardFileExtension();
         Collection<String> sourceDirs = WeavingContext.getConfiguration().getSourceDirs(_scriptingEngine);
@@ -203,7 +207,7 @@ public class ThrowawayClassloader extend
         reloadingMetaData.setScriptingEngine(_scriptingEngine);
 
         WeavingContext.getFileChangedDaemon().getClassMap().put(className, reloadingMetaData);
-         reloadingMetaData.executeLastLoaded();
+        reloadingMetaData.executeLastLoaded();
         return retVal;
     }