Title: Can't import java class from a mixed directory
Type: Severity: critical
Components: Core Versions: Jython 2.5
Status: open Resolution: remind
Dependencies: Superseder:
Assigned To: fwierzbicki Nosy List: curtis, edanuff, fwierzbicki, jeff.allen, mhagger, mvera, niall_kelly, ttsounis
Priority: normal Keywords: patch

Created on 2008-01-24.12:33:11 by niall_kelly, last changed 2018-03-21.22:08:35 by jeff.allen.

File name Uploaded Description Edit Remove
foo.tar ttsounis, 2009-09-17.11:48:00 Foo package inside jython2.5.0/Lib/site-packages directory
issue1878866-test.tar.gz mhagger, 2011-05-04.17:03:24 Test case for an instance of this issue
import.patch mhagger, 2011-05-04.17:07:42 Patch that may or may not fix the problem
test.patch mhagger, 2011-05-04.18:02:53 Patch adding test case to Jython test suite
msg2063 (view) Author: Niall Kelly (niall_kelly) Date: 2008-01-24.12:33:11
I have a directory containing both java class and jython scripts. The ancestor of the directory is on the class path and python path. When I try to import the java class  I get an ImportError (ImportError: cannot import name X). The jython files in the same directory import fine. 
This is using Jython 2.2.1 on Linux. This would previously work under jython 2.1
msg4394 (view) Author: Curtis Thompson (curtis) Date: 2009-03-30.18:52:00
Can you try this with latest 2.5b3 jar and see if this is still an issue?

If this is still an issue, can you provide a test case that fails?
msg5184 (view) Author: Thanos Tsounis (ttsounis) Date: 2009-09-17.11:48:00

I have a similar problem in Linux with jython 2.5. Inside
jython2.5.0/Lib/site-packages a have a foo directory where there is a
Java class (Bar.class) and a jython class ( i have also put an
empty file. In the jython interpreter environment I can
always import Bar like this: "from foo import Bar" however I cannot
import BarPy. If I delete the java class from the directory then I can
import the jython script
msg6246 (view) Author: Ed Anuff (edanuff) Date: 2010-11-11.20:21:33
I'm seeing this in 2.5.2rc2.
msg6521 (view) Author: Michael Haggerty (mhagger) Date: 2011-05-04.17:03:24
In either 2.2.1 or in 2.6a0+ (trunk r7292) I am usually successful importing from a mixed directory.  But in both of those versions I see an ImportError in the following, more specific scenario.  When the current directory contains the following files:


then importing Foo fails with an ImportError; e.g., when run via

    jython -c 'from a.b import Foo'


    jython -c 'import a.b.Foo'

However, if I add a file a/Foobar.class, then both of the imports succeed.

The problem seems to be in org.python.core.packagecache.PathPackageManager.  In particular, there seems to be an assumption in PackageExistsFileFilter that a directory is pure Python if it includes Python code but no Java code, even if one of its subdirectories includes Java code.

I will attach a tar file that illustrates the problem; simply unpack it in a clean directory then run one of the jython commands as shown above.  The tarball also includes some scripts for playing around with variations on the theme.  Let me know if you need more information.
msg6522 (view) Author: Michael Haggerty (mhagger) Date: 2011-05-04.17:07:42
Attached is a patch that fixes the problem for me in the very limited scenario described in my previous comment.  The patch causes PackageExistsFileFilter to consider any directory that contains a subdirectory to potentially contain Java classes.  I do not know enough about the code to assess whether the patch might horribly break other things.
msg6523 (view) Author: Michael Haggerty (mhagger) Date: 2011-05-04.18:02:53
At the suggestion of jimbaker, I hereby attach a patch adding a test for the issue just described.  The test fails under trunk r7292 but passes if my previous patch is applied.
msg7498 (view) Author: mvera (mvera) Date: 2012-10-31.13:31:20
I experienced a similar problem, the java class could be found but not the python module. The application worked fine under Windows7 32bits / Tomcat.

The problem exists on the platform windows 2008 64bits / websphere 7 ND 64bits
msg7499 (view) Author: mvera (mvera) Date: 2012-10-31.13:33:04
My bug on websphere occured with version 2.5.3.
msg7609 (view) Author: Michael Haggerty (mhagger) Date: 2013-02-04.16:15:16
I attached a patch and a test case to this bug in May 2011.  What is the next step, and how can I help get there?
msg7610 (view) Author: Frank Wierzbicki (fwierzbicki) Date: 2013-02-04.16:43:55
Hi Michael Haggerty, sorry this has stagnated here for so long, outside of a several month contract to get 2.7 pushed along my time for Jython has been a little thin. I'll try to do better. As I head towards a 2.7 final I plan to triage all outstanding bugs. Bugs with patches (like this one) will get a look first. I plan to put out a 2.7 beta1 this week, I'll try to have a look at this patch before that, but if I don't get to it I will definitely have a look soon after.

Sorry again for the slowness.
msg7611 (view) Author: Frank Wierzbicki (fwierzbicki) Date: 2013-02-04.16:46:12
BTW the reason I hesitate on this is that the import system is especially tricky to fix. Most of the time fixing one thing breaks other things. It's better to apply patches like this in the context of fixing all import related issues at once.
msg11836 (view) Author: Jeff Allen (jeff.allen) Date: 2018-03-21.22:08:35
See also #2654 and #2455.
Date User Action Args
2018-03-21 22:08:35jeff.allensetnosy: + jeff.allen
messages: + msg11836
2013-02-19 23:12:52fwierzbickisetresolution: remind
versions: + Jython 2.5, - 2.5.3b2
2013-02-04 16:46:12fwierzbickisetmessages: + msg7611
2013-02-04 16:43:55fwierzbickisetmessages: + msg7610
2013-02-04 16:15:17mhaggersetmessages: + msg7609
2012-10-31 13:33:04mverasetmessages: + msg7499
2012-10-31 13:31:21mverasetnosy: + mvera
messages: + msg7498
versions: + 2.5.3b2
2012-08-10 18:37:55fwierzbickisetassignee: fwierzbicki
nosy: + fwierzbicki
2011-05-04 18:02:54mhaggersetfiles: + test.patch
messages: + msg6523
2011-05-04 17:07:42mhaggersetfiles: + import.patch
keywords: + patch
messages: + msg6522
2011-05-04 17:03:25mhaggersetfiles: + issue1878866-test.tar.gz
nosy: + mhagger
messages: + msg6521
2010-11-11 20:21:33edanuffsetnosy: + edanuff
messages: + msg6246
2009-09-17 11:48:49ttsounissetseverity: normal -> critical
2009-09-17 11:48:00ttsounissetfiles: + foo.tar
nosy: + ttsounis
messages: + msg5184
2009-03-30 18:52:00curtissetnosy: + curtis
messages: + msg4394
2008-01-24 12:33:11niall_kellycreate