Bug 51745 - getLastModified of compilation context returns 0 on Android and it issues all time recompilation
Summary: getLastModified of compilation context returns 0 on Android and it issues all...
Status: RESOLVED WONTFIX
Alias: None
Product: Tomcat 7
Classification: Unclassified
Component: Jasper (show other bugs)
Version: 7.0.20
Hardware: Other other
: P2 normal (vote)
Target Milestone: ---
Assignee: Tomcat Developers Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-08-31 01:02 UTC by d rogatkin
Modified: 2011-09-01 10:58 UTC (History)
0 users



Attachments
Possible patch (881 bytes, patch)
2011-08-31 15:28 UTC, Mark Thomas
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description d rogatkin 2011-08-31 01:02:53 UTC
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();
				}
			}
Comment 1 Mark Thomas 2011-08-31 15:28:08 UTC
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.
Comment 2 d rogatkin 2011-08-31 18:16:32 UTC
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
Comment 3 d rogatkin 2011-09-01 01:15:24 UTC
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.
Comment 4 Mark Thomas 2011-09-01 10:58:51 UTC
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.