Issue1373

classification
Title: Jython ClassLoader getRessource does not work
Type: Severity: major
Components: Core Versions: 2.5.1
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: amak, boisgera, c.cerbo, fwierzbicki, jdeolive, pjenvey
Priority: Keywords: patch

Created on 2009-06-11.09:16:40 by boisgera, last changed 2010-02-15.13:19:05 by c.cerbo.

Files
File name Uploaded Description Edit Remove
pck.jar boisgera, 2009-06-11.09:16:39
implement_systpathjavaloader_getresource.patch jdeolive, 2009-11-05.02:45:23
bug1373.jar jdeolive, 2009-11-05.02:46:24 jar required for test case, located in Lib/tests
Messages
msg4809 (view) Author: (boisgera) Date: 2009-06-11.09:16:39
Resource files in jars that are added via sys.path won't be found by
getRessource. Consider the pck.jar file that contains pck/Main.java and
the resource pck/Main.txt:

    >>> import sys
    >>> sys.path.append("pck.jar")
    >>> import pck
    *sys-package-mgr*: processing new jar,
'/home/boisgera/SANDBOX/JYTHON-BUGS/RESOURCE/pck.jar'
    >>> pck.Main.getResource("Main.txt") is None
    True
    >>> pck.Main.getClassLoader()
    org.python.core.SyspathJavaLoader@13d21d6

On the other hand, if 'pck.jar' is already in the CLASSPATH, I end up with:

    >>> import pck
    >>> pck.Main.getResource("Main.txt")
   
jar:file:/home/boisgera/SANDBOX/JYTHON-BUGS/RESOURCE/pck.jar!/pck/Main.txt
    >>> pck.Main.getClassLoader()
    sun.misc.Launcher$AppClassLoader@17182c1

I guess that 'findResource' should be implemented in SyspathJavaLoader
for this to work. The method 'getResourceAsStream' being already
implemented, I guess that most of the work has already been done ... right ?
msg4846 (view) Author: Philip Jenvey (pjenvey) Date: 2009-06-21.23:14:25
Yea it looks like all the work is done it just needs a reshuffling of 
implemented methods
msg5301 (view) Author: Justin Deoliveira (jdeolive) Date: 2009-11-05.02:45:23
Included in the patch is a test case which requires a jar identical to the 
pck.jar file attached to this issue, but compiled under java 5 and renamed 
to bug1373.jar. I ran regrtest with the patch applied and saw no failures.
msg5528 (view) Author: Costantino Cerbo (c.cerbo) Date: 2010-02-15.13:18:52
This problem persists also with the new SyspathJavaLoader but the attached patch is obsolete. 

I've written a new patch:

Index: src/org/python/core/SyspathJavaLoader.java
===================================================================
--- src/org/python/core/SyspathJavaLoader.java	(revision 6980)
+++ src/org/python/core/SyspathJavaLoader.java	(working copy)
@@ -134,7 +134,7 @@
                 ZipEntry ze = archive.getEntry(entryRes);
                 if (ze != null) {
                 	try {
-						return new URL("jar:" + entry.__str__().toString() + "!/" + entryRes);
+						return new URL("jar:file:" + entry.__str__().toString() + "!/" + entryRes);
 					} catch (MalformedURLException e) {
 						throw new RuntimeException(e);
 					}
@@ -143,7 +143,11 @@
             }
             String dir = sys.getPath(entry.__str__().toString());
             try {
-				return new File(dir, res).toURI().toURL();
+				File resource = new File(dir, res);
+				if (!resource.exists()) {
+					continue;
+				}
+				return resource.toURI().toURL();
 			} catch (MalformedURLException e) {
 				throw new RuntimeException(e);
 			}


The unit test may be "recycled"
History
Date User Action Args
2010-02-15 13:19:05c.cerbosetseverity: normal -> major
versions: + 2.5.1, - 25rc4
2010-02-15 13:18:54c.cerbosetnosy: + c.cerbo
messages: + msg5528
2009-11-10 19:13:00fwierzbickisetnosy: + fwierzbicki
2009-11-10 17:02:17amaksetnosy: + amak
2009-11-05 02:46:24jdeolivesetfiles: + bug1373.jar
2009-11-05 02:45:25jdeolivesetfiles: + implement_systpathjavaloader_getresource.patch
nosy: + jdeolive
messages: + msg5301
keywords: + patch
2009-06-21 23:14:25pjenveysetnosy: + pjenvey
messages: + msg4846
2009-06-11 09:16:40boisgeracreate