Bug 20198 - java.security.CodeSource.getLocation output is different than expected
Summary: java.security.CodeSource.getLocation output is different than expected
Status: RESOLVED FIXED
Alias: None
Product: classpath
Classification: Unclassified
Component: classpath (show other bugs)
Version: unspecified
: P2 normal
Target Milestone: 0.90
Assignee: tromey@redhat.com
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-02-24 18:00 UTC by Ben Konrath
Modified: 2006-01-18 00:19 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2005-09-16 23:10:50


Attachments
Proposed patch (579 bytes, patch)
2005-07-24 19:49 UTC, Anthony Green
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Ben Konrath 2005-02-24 18:00:20 UTC
GCJ version:

% gij4 --version
gij (GNU libgcj) version 4.0.0 20050217 (Red Hat 4.0.0-0.27)

Test class:

public class Test {
	public static void main(String[] args) {
		System.out.println(Test.class.getProtectionDomain().
                getCodeSource().getLocation());
	}
}

With Sun VM 1.4.2_06 I get:

% j2sdk1.4.2_06/bin/java Test
file:/home/bkonrath/

With GCJ I get: 

% gij4 Test
file:./

I also noticed that the SUN vm returns a URL that has symlinks resolved. Let me
know if you need more info or if I should file this bug somewhere else.
Comment 1 Anthony Green 2005-07-24 19:49:00 UTC
Created attachment 9352 [details]
Proposed patch

This patch makes your test program emit an absolute path.

I'm not sure it's 100% correct.  For instance, perhaps we should canonicalize
the path in addition to makeing it absolute.  Also, perhaps this should happen
in URLClassLoader instead of the system loader.  Hopefully a discussion will
happen on this thread:

http://gcc.gnu.org/ml/java-patches/2005-q3/msg00144.html
Comment 2 Andrew Pinski 2005-07-26 22:10:59 UTC
This is a classpath issue and should be moved to classpath/classpath but I cannot move it for some 
reason.
Comment 3 Andrew Pinski 2005-07-26 23:19:41 UTC
Moving to classpath/classpath.
Comment 4 Anthony Green 2005-09-16 23:10:50 UTC
(In reply to comment #1)
> Created an attachment (id=9352)
> Proposed patch
> 
> This patch makes your test program emit an absolute path.
> 
> I'm not sure it's 100% correct.  For instance, perhaps we should canonicalize
> the path in addition to makeing it absolute.  Also, perhaps this should happen
> in URLClassLoader instead of the system loader.  Hopefully a discussion will
> happen on this thread:
> 
> http://gcc.gnu.org/ml/java-patches/2005-q3/msg00144.html
> 


I just checked in a patch for a related fix.   The test case look like this:

public class bug
{
    public static void main (String args[]) throws Exception
    {
        String urlString =
bug.class.getClassLoader().getResource("bug.class").toExternalForm ();
        System.out.println (urlString);
    }
}

Before patch:

$ gij bug
file:./bug.class

After patch:

$ gij bug
file:/home/green/FSF/HEAD/bug.class

Unfortunately it doesn't fix this bug (although the original patch attached to
this bug _does_).

I'll figure out what else is needed for this bug.

AG
Comment 5 cvs-commit@developer.classpath.org 2005-09-16 23:12:41 UTC
Subject: Bug 20198

CVSROOT:	/cvsroot/classpath
Module name:	classpath
Branch: 	
Changes by:	Anthony Green <green@savannah.gnu.org>	05/09/16 22:52:18

Modified files:
	.              : ChangeLog 
	java/net       : URLClassLoader.java 

Log message:
	2005-09-15  Anthony Green  <green@redhat.com>
	
	PR libgcj/20198
	* java/net/URLClassLoader.java (FileURLLoader.getResource): File
	resources should all have canonicalized names.

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/classpath/classpath/ChangeLog.diff?tr1=1.4834&tr2=1.4835&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/classpath/classpath/java/net/URLClassLoader.java.diff?tr1=1.36&tr2=1.37&r1=text&r2=text




Comment 6 Tom Tromey 2006-01-17 01:17:20 UTC
Testing a patch.
Comment 7 Tom Tromey 2006-01-17 19:59:36 UTC
Subject: Bug 20198

Author: tromey
Date: Tue Jan 17 19:59:29 2006
New Revision: 109837

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=109837
Log:
	PR classpath/20198:
	* java/net/URLClassLoader.java (FileURLLoader): Added argument.
	(JarURLLoader): Likewise.
	(addURLImpl): Canonicalize file URLs.

Modified:
    branches/gcc-4_1-branch/libjava/ChangeLog
    branches/gcc-4_1-branch/libjava/java/net/URLClassLoader.java

Comment 8 Tom Tromey 2006-01-17 23:25:17 UTC
Subject: Bug 20198

Author: tromey
Date: Tue Jan 17 23:25:12 2006
New Revision: 109844

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=109844
Log:
	PR classpath/20198:
	* java/net/URLClassLoader.java (FileURLLoader): Added argument.
	(JarURLLoader): Likewise.
	(addURLImpl): Canonicalize file URLs.

Modified:
    trunk/libjava/ChangeLog
    trunk/libjava/java/net/URLClassLoader.java

Comment 9 Tom Tromey 2006-01-18 00:19:53 UTC
Fixed in classpath cvs; also in gcc 4.1.
Comment 10 cvs-commit@developer.classpath.org 2006-01-18 00:19:57 UTC
Subject: Bug 20198

CVSROOT:	/cvsroot/classpath
Module name:	classpath
Branch: 	
Changes by:	Tom Tromey <tromey@savannah.gnu.org>	06/01/18 00:19:13

Modified files:
	.              : ChangeLog 
	java/net       : URLClassLoader.java 

Log message:
	PR classpath/20198:
	* java/net/URLClassLoader.java (FileURLLoader): Added argument.
	(JarURLLoader): Likewise.
	(addURLImpl): Canonicalize file URLs.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/classpath/classpath/ChangeLog.diff?tr1=1.6106&tr2=1.6107&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/classpath/classpath/java/net/URLClassLoader.java.diff?tr1=1.43&tr2=1.44&r1=text&r2=text