URLConnection implementation org.apache.harmony.luni.internal.net.www.protocol.file.FileURLConnection returns 0 for getLastModified and it breaks normal working of the wrapper method in compilation context. It seems happens on Android platfrom 2.1 and can happen for other. So I modified the method to avoid the problem like below: try { URL jspUrl = getResource(resource); if (jspUrl == null) { incrementRemoved(); return Long.valueOf(result); } File resFile = new File(jspUrl.getFile()); // TJWS on Android if (resFile.exists()) { result = resFile.lastModified(); } else { uc = jspUrl.openConnection(); if (uc instanceof JarURLConnection) { result = ((JarURLConnection) uc).getJarEntry().getTime(); } else { result = uc.getLastModified(); } }
Created attachment 27447 [details] Possible patch I'm not a fan of adding workarounds in Tomcat for bugs in any third-party product (JVM, OS, database etc). The root cause is a harmony bug: https://issues.apache.org/jira/browse/HARMONY-6504 which has been fixed for a while. However, as far as I can tell, this has not been ported to Android. If it were to be patched, the patch would probably be along the lines of the attachment. It would be helpful if you could confirm that the proposed fix addresses the issue you are seeing. I'm struggling to see how this behaviour could ever be something other than a bug in the JRE.
I agree that the proposed solution is a workaround of the bug in connection implementation. However it works for both mobile and desktop platforms (validated) and can be consider lighter solution, since doesn't require ping and close connection in most use cases. Another solution can be wrapping buggy connection in something taking care of the bug. Although it can look elegant, it can bring extra overhead and make code less readable. Anyway I do not insist on fixing problem since I need to modify the class anyway, since I use different Java compiler
I have checked with Android team, and it looks like Harmony bug was fixed for Android 2.3 (Gingerbread), however still exists for earlier Androids. Perhaps this problem can be closed.
If the issue is fixed in Gingerbread then I don't think there is a case for work-around this in Tomcat. The patches will, of course, remain available in Bugzilla should anyone wish to use them locally.