Bug 51584 - Crash (infinite loop) when files starting with '#' are in the library tree
Crash (infinite loop) when files starting with '#' are in the library tree
Status: RESOLVED FIXED
Product: Tomcat 7
Classification: Unclassified
Component: Catalina
trunk
PC All
: P2 major (vote)
: ---
Assigned To: Tomcat Developers Mailing List
:
Depends on:
Blocks:
  Show dependency tree
 
Reported: 2011-07-29 15:34 UTC by Steven R. Loomis
Modified: 2012-05-18 09:02 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Steven R. Loomis 2011-07-29 15:34:27 UTC
Situation:
 stray text file in my /WEB-INF/classes/...../ directory named "#SurveyMain.java#"     ( It was a backup/autosaved source file, and eclipse 'helpfully' deployed it. ) 

 
 causes crash on startup in tomcat 7.0.6, 7.0.19 and 7.0.20-dev (1151601M). - out of memory.


Added this test to .20-dev:

Index: org/apache/catalina/startup/ContextConfig.java
===================================================================
--- org/apache/catalina/startup/ContextConfig.java	(revision 1151601)
+++ org/apache/catalina/startup/ContextConfig.java	(working copy)
@@ -1902,6 +1902,7 @@
                 while (dirs.hasMoreElements()) {
                     String dir = dirs.nextElement();
                     URL dirUrl = new URL(url.toString() + '/' + dir);
+                    System.err.println("Processing: " + url.toString() + '/' + dir);
                     processAnnotationsJndi(dirUrl, fragment);
                 }
                 

Printed tons of lines… at startup…


Processing: jndi:/localhost/cldr-apps/WEB-INF/classes/org/unicode/cldr/web/#SurveyMain.java#/#SurveyMain.java#/#SurveyMain.java#/#SurveyMain.java#/#SurveyMain.java#/#SurveyMain.java#/#SurveyMain.java#/#SurveyMain.java#/#SurveyMain.java#/#SurveyMain.java#/#SurveyMain.java#/#SurveyMain.java#/#SurveyMain.java#/#SurveyMain.java#/#SurveyMain.java#/#SurveyMain.java#/#SurveyMain.java#/#SurveyMain.java#/#SurveyMain.java#/#SurveyMain.java#/#SurveyMain.java#/#SurveyMain.java#/#SurveyMain.java#/#SurveyMain.java#/#SurveyMain.java#/#SurveyMain.java#/#SurveyMain.java#/#SurveyMain.java#/#SurveyMain.java#/#SurveyMain.java#/#SurveyMain.java#/#SurveyMain.java#/#SurveyMain.java#/#SurveyMain.java#/#SurveyMain.java#/#SurveyMain.java#/#SurveyMain.java#/#SurveyMain.java#/#SurveyMain.java#/#SurveyMain.java#/#SurveyMain.java#/#SurveyMain.java#/#SurveyMain.java#/#SurveyMain.java#/#SurveyMain.java#/#SurveyMain.java#/#SurveyMain.java#/#SurveyMain.java#/#SurveyMain.java#/#SurveyMain.java#/#SurveyMain.java#/#SurveyMain.java#/#SurveyMain.java#/#SurveyMain.java#/#SurveyMain.java#/#SurveyMain.java#/#SurveyMain.java#/#SurveyMain.java#/#SurveyMain.java#/#SurveyMain.java#/#SurveyMain.java#/#SurveyMain.java#/#SurveyMain.java#/....

Then crashed as before…

java.lang.OutOfMemoryError: Java heap space
	at java.util.Arrays.copyOfRange(Arrays.java:3209)
	at java.lang.String.<init>(String.java:215)
	at java.lang.StringBuilder.toString(StringBuilder.java:430)
	at java.io.UnixFileSystem.resolve(UnixFileSystem.java:93)
	at java.io.File.<init>(File.java:312)
	at org.apache.naming.resources.FileDirContext.list(FileDirContext.java:871)
	at org.apache.naming.resources.FileDirContext.list(FileDirContext.java:304)
	at org.apache.naming.resources.ProxyDirContext.list(ProxyDirContext.java:506)
	at org.apache.naming.resources.DirContextURLConnection.list(DirContextURLConnection.java:444)
	at org.apache.catalina.startup.ContextConfig.processAnnotationsJndi(ContextConfig.java:1901)
	at org.apache.catalina.startup.ContextConfig.processAnnotationsJndi(ContextConfig.java:1906)
	at org.apache.catalina.startup.ContextConfig.processAnnotationsJndi(ContextConfig.java:1906)
	at org.apache.catalina.startup.ContextConfig.processAnnotationsJndi(ContextConfig.java:1906)
	at org.apache.catalina.startup.ContextConfig.processAnnotationsJndi(ContextConfig.java:1906)
	at org.apache.catalina.startup.ContextConfig.processAnnotationsJndi(ContextConfig.java:1906)
	at org.apache.catalina.startup.ContextConfig.processAnnotationsJndi(ContextConfig.java:1906)
	at org.apache.catalina.startup.ContextConfig.processAnnotationsJndi(ContextConfig.java:1906)
	at org.apache.catalina.startup.ContextConfig.processAnnotationsJndi(ContextConfig.java:1906)
	at org.apache.catalina.startup.ContextConfig.processAnnotationsJndi(ContextConfig.java:1906)
	at org.apache.catalina.startup.ContextConfig.processAnnotationsJndi(ContextConfig.java:1906)
	at org.apache.catalina.startup.ContextConfig.processAnnotationsJndi(ContextConfig.java:1906)
	at org.apache.catalina.startup.ContextConfig.processAnnotationsJndi(ContextConfig.java:1906)
	at org.apache.catalina.startup.ContextConfig.processAnnotationsJndi(ContextConfig.java:1906)
	at org.apache.catalina.startup.ContextConfig.processAnnotationsJndi(ContextConfig.java:1906)
	at org.apache.catalina.startup.ContextConfig.processAnnotationsJndi(ContextConfig.java:1906)
	at org.apache.catalina.startup.ContextConfig.processAnnotationsJndi(ContextConfig.java:1906)
	at org.apache.catalina.startup.ContextConfig.processAnnotationsJndi(ContextConfig.java:1906)
	at org.apache.catalina.startup.ContextConfig.processAnnotationsJndi(ContextConfig.java:1906)
	at org.apache.catalina.startup.ContextConfig.processAnnotationsJndi(ContextConfig.java:1906)
	at org.apache.catalina.startup.ContextConfig.processAnnotationsJndi(ContextConfig.java:1906)
	at org.apache.catalina.startup.ContextConfig.processAnnotationsJndi(ContextConfig.java:1906)
	at org.apache.catalina.startup.ContextConfig.processAnnotationsJndi(ContextConfig.java:1906)



I think the problem is that the URL generated contains a '#' and so file:// interprets it as a fragment and not as a path.

Quick patch:

Index: java/org/apache/catalina/startup/ContextConfig.java
===================================================================
--- java/org/apache/catalina/startup/ContextConfig.java	(revision 1151601)
+++ java/org/apache/catalina/startup/ContextConfig.java	(working copy)
@@ -1901,7 +1901,11 @@
                 Enumeration<String> dirs = dcUrlConn.list();
                 while (dirs.hasMoreElements()) {
                     String dir = dirs.nextElement();
+                    if(dir.startsWith("#")) {
+                        continue;
+                    }
                     URL dirUrl = new URL(url.toString() + '/' + dir);
+                    //System.err.println("Processing: " + dirUrl.toString());
                     processAnnotationsJndi(dirUrl, fragment);
                 }
Comment 1 Mark Thomas 2011-07-31 17:00:49 UTC
Thanks for the report.

The fix needs to be at a lower level than the patch you suggest to address the root cause rather than one of the symptoms.

The patch has been applied to 7.0.x and will be included in 7.0.20 onwards.
Comment 2 Steven R. Loomis 2011-08-01 13:48:05 UTC
(In reply to comment #1)
> Thanks for the report.
> 
> The fix needs to be at a lower level than the patch you suggest to address the
> root cause rather than one of the symptoms.

I don't doubt it at all. 

> The patch has been applied to 7.0.x and will be included in 7.0.20 onwards.

Thanks! I was surprised to find this was a unique find. But perhaps few people use  vim + eclipse + tomcat.  I don't, but apparently I edited one source file with vim.
Comment 3 Konstantin Kolinko 2012-05-18 09:02:24 UTC
Just noting that the fix for this issue (r1152593) was incomplete and caused regression - bug 53257. See further discussion there.