Author: hlship
Date: Wed Oct 26 17:46:44 2011
New Revision: 1189336

URL: http://svn.apache.org/viewvc?rev=1189336&view=rev
Log:
TAP5-1729: Sometimes YUICompressor can fail with java.util.EmptyStackException

Modified:
    
tapestry/tapestry5/trunk/tapestry-yuicompressor/src/main/java/org/apache/tapestry5/internal/yuicompressor/JavaScriptResourceMinimizer.java

Modified: 
tapestry/tapestry5/trunk/tapestry-yuicompressor/src/main/java/org/apache/tapestry5/internal/yuicompressor/JavaScriptResourceMinimizer.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-yuicompressor/src/main/java/org/apache/tapestry5/internal/yuicompressor/JavaScriptResourceMinimizer.java?rev=1189336&r1=1189335&r2=1189336&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-yuicompressor/src/main/java/org/apache/tapestry5/internal/yuicompressor/JavaScriptResourceMinimizer.java
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-yuicompressor/src/main/java/org/apache/tapestry5/internal/yuicompressor/JavaScriptResourceMinimizer.java
 Wed Oct 26 17:46:44 2011
@@ -17,6 +17,7 @@ package org.apache.tapestry5.internal.yu
 import com.yahoo.platform.yui.compressor.JavaScriptCompressor;
 import org.apache.tapestry5.ioc.OperationTracker;
 import org.apache.tapestry5.ioc.internal.util.CollectionFactory;
+import org.apache.tapestry5.ioc.internal.util.InternalUtils;
 import org.apache.tapestry5.services.assets.StreamableResource;
 import org.mozilla.javascript.ErrorReporter;
 import org.mozilla.javascript.EvaluatorException;
@@ -101,11 +102,42 @@ public class JavaScriptResourceMinimizer
             logInputLines(resource, errorLines);
 
             throw ex;
+        } catch (Exception ex)
+        {
+            logger.error(String.format("Exception minimizing %s: %s", 
resource, InternalUtils.toMessage(ex), ex));
+
+            streamUnminimized(resource, output);
         }
 
         reader.close();
     }
 
+    private void streamUnminimized(StreamableResource resource, Writer output) 
throws IOException
+    {
+        Reader reader = toReader(resource);
+
+        char[] buffer = new char[5000];
+
+        try
+        {
+
+            while (true)
+            {
+                int length = reader.read(buffer);
+
+                if (length < 0)
+                {
+                    break;
+                }
+
+                output.write(buffer, 0.length);
+            }
+        } finally
+        {
+            reader.close();
+        }
+    }
+
     private void logInputLines(StreamableResource resource, Set<Integer> lines)
     {
         int last = -1;


Reply via email to