Craig,
Here's one step towards what you were asking for. It's a standalone test case of the
problem. I've written this because, judging from some of the issues that were
occuring with Cocoon, I have a feeling that this problem is System/Java version
dependent. The problem has been seen on Solaris, MacOS X and Windows with versions
1.2.2 and 1.3, but it may be only in certain combinations.
If this test case reproduces the problem on your system, then were going in the right
direction. If not, then we'll never produce a test case for you to be able to test.
Here's the code:
import java.io.File;
import java.net.URL;
import java.net.URLClassLoader;
public class Test {
public static void main(String args[]) {
System.out.println("STARTED");
try {
String filename = "jac.zip";
String filepath2 = "/Users/stuart/";
String filepath3 = "Documents/../temp/";
String filepath = filepath2 + filepath3;
System.out.println("filepath = " + filepath);
System.out.println("filepath2 = " + filepath2);
System.out.println("filepath3 = " + filepath3);
System.out.println("filename = " + filename);
File file1 = new File(filepath, filename);
System.out.println("file1 = new File(filepath, filename) = " +
file1.toString());
System.out.println("file1.getAbsolutePath() = " + file1.getAbsolutePath());
System.out.println("file1.getCanonicalPath() = " +
file1.getCanonicalPath());
URL url1 = new URL("file:" + filepath);
URL url2 = new URL("file", null, -1, filepath);
URL url3 = new URL("file", null, filepath);
URL url4 = new URL(new URL("file:"+filepath2), filepath3);
System.out.println("url1 = new URL(\"file:\" + filepath) = " + url1);
System.out.println("url2 = new URL(\"file:\", null, -1, filepath) = " +
url2);
System.out.println("url3 = new URL(\"file:\", null, filepath) = " + url3);
System.out.println("url4 = new URL(new URL(\"file:\"+filepath2),
filepath3) = " + url4);
//URL inUrls [] = {url1, url2, url3, url4};
URL inUrls1 [] = {url2,url3};
URL inUrls2 [] = {url1,url4};
URLClassLoader classLoader1 = new URLClassLoader(inUrls1);
URLClassLoader classLoader2 = new URLClassLoader(inUrls2);
URL outUrls1 [] = classLoader1.getURLs();
URL outUrls2 [] = classLoader2.getURLs();
for (int i = 0; i < outUrls1.length; i++) {
System.out.println("outUrls1["+i+"] = " + outUrls1[i]);
}
for (int i = 0; i < outUrls2.length; i++) {
System.out.println("outUrls2["+i+"] = " + outUrls2[i]);
}
System.out.println("Resource found by classloader1 = " +
classLoader1.findResource(filename));
System.out.println("Resource found by classloader2 = " +
classLoader2.findResource(filename));
} catch (Exception e) {
System.out.println(e);
}
System.exit(0);
}
}
Please substitute in appropriate values for filepath2, filepath3 and filename.
filepath3 should contain a "../" element, filepath + filename should point to a real
file on your system.
My test results are:
STARTED
filepath = /Users/stuart/Documents/../temp/
filepath2 = /Users/stuart/
filepath3 = Documents/../temp/
filename = jac.zip
file1 = new File(filepath, filename) = /Users/stuart/Documents/../temp/jac.zip
file1.getAbsolutePath() = /Users/stuart/Documents/../temp/jac.zip
file1.getCanonicalPath() = /Users/stuart/temp/jac.zip
url1 = new URL("file:" + filepath) = file:/Users/stuart/temp/
url2 = new URL("file:", null, -1, filepath) = file:/Users/stuart/Documents/../temp/
url3 = new URL("file:", null, filepath) = file:/Users/stuart/Documents/../temp/
url4 = new URL(new URL("file:"+filepath2), filepath3) = file:/Users/stuart/temp/
outUrls1[0] = file:/Users/stuart/Documents/../temp/
outUrls1[1] = file:/Users/stuart/Documents/../temp/
outUrls2[0] = file:/Users/stuart/temp/
outUrls2[1] = file:/Users/stuart/temp/
Resource found by classloader1 = null
Resource found by classloader2 = file:/Users/stuart/temp/jac.zip
Stuart.
On Thursday, December 21, 2000, at 06:56 PM, Craig R. McClanahan wrote:
>
>
> Stuart Roebuck wrote:
>
> > In the course of fixing a problem I was having getting Apache Cocoon to run, I
>came across a
> bug in Java in the File.toURL() method. This fault, combined with the use of the
> URLClassLoader resulted in a classloading issue.
> >
>
> Stuart,
>
> I'm trying to create a simple, reproducible test case that causes Tomcat 4.0 to fail
> because of this -- but so far, I have not been able to.
>
> For example, I would assume that the following scenario should fail due to this
>problem:
> * Run on Linux (RH 6.2) + JDK 1.2.2
> * Do *not* set the CATALINA_HOME environment variable
> * Set current directory to where Tomcat 4.0 is installed
> * Start it by typing "./bin/catalina.sh start".
>
> This would cause CATALINA_HOME (and therefore the "catalina.home" system property)
>to
> be set to "./bin/..", which would cause all the URLs in the "system" class loader --
>the one
> created from JAR files in the "bin" directory -- to have absolute pathnames with
>".." in
> them, which should trigger this problem.
>
> Yet, it still runs correctly. Can you help me identify a failure case?
>
> Craig
>
>
>
-------------------------------------------------------------------------
Stuart Roebuck [EMAIL PROTECTED]
Lead Developer Mac OS X, Java, XML, etc.
ADOLOS http://www.adolos.com/