Question

Legacy Java 5 application now throwing exceptions after moving to Java 7. I have this code in a Java class to return a URL. The URL can either be a filepath or the codebase for the application. An error is thrown when the URL is a filepath. What is going wrong here? It worked perfectly in Java 5.

Was it helpful?

Solution

For a long (long) time Sun had been saying "Don't put application resources in the application installation directory!".

They decided to make that advice a little more formalized some time during 1.6 (AFAIR) by ensuring that no applet or app. deployed using JWS could get the installation path even if it already had declared all permissions! For apps. that tried, the JVM will 'lie' and point directly back to the place from which the Jars were first downloaded, even if they were cached locally and the JVM was using the files from the cache.

So, (according to that decision) the app. is broken and needs fixing. If you raised a bug report, it would be closed as 'not a bug'.

On a side note:

URL fileurl = new URL(getCode() + file);

Should probably be:

URL fileurl = new URL(getCode(), file);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top