-
Notifications
You must be signed in to change notification settings - Fork 183
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Import * statement failed to work on Jython 2.7.2 #309
Comments
What is the JDK version for both tests? What happens if you revert JDK to earlier version? |
The JDK version is as below. |
I will check if the issue can be recreated with Jython V2.7.2 and other JDK level. |
Ah ok. I saw a similar issue for JDK21. So I doubt it's the same issue... |
I confirmed the issue is recreated with older version. Let me add information about JDK. I use IBM Java . |
@jeff5 assuming this worked in 2.7 and before, this seems like a bug. |
It's the same in the development tip locally. |
@jeff5 On Mac, this can be recreated as follows. Mac
Windows
|
@jeff5 I also recreated on Windows. Stanalone
Installer
|
Hello are there any updates ? |
Standalone mode was deliberately designed to not support java imports of the form The reason for this are application containers like WildFly, Payara, Websphere and other more complex java applications. Each of those has its own layout and handling of the class path and class loaders. It would be impossible for jython to completely scan the whole class path for packages. And it would considerably slow down the startup process. Hope to have helped to spot the difference. |
@ohumbel Thank you for the clarification. I was somewhat surprised by this limitation; looking at the Package Java API, indeed no method there can list the classes in a given package. Apparently, class loaders do not provide this functionality and workarounds are expensive. |
Is it correct that error message will be improved and user guide will be also updated ? |
No promise from my side, but I have loose plans to clean up the user guide and then I would include this bit. Fixing the error is rather low priority and everyone is busy :) However I think this issue will stay open until it is resolved eventually. If you want to make a PR, that would be very welcome. @jeff5: It would be good if you could confirm the resolution (i.e. via improving the error message)(, or suggest an alternative). |
I second Stefan's thanks @ohumbel, that's a really useful insight. And "standalone" was what I was missing earlier. The way that Python packages differ from Java's concept is a continual source of surprises: superficially similar, then not quite the same thing. In some ways, Java's concept is more robust: it will look for what you explicitly request, and in as many remote corners as it has class loaders for, but it won't enumerate what is available. Java packages are somewhat like Python namepace packages, in having multiple loci, but those are confined to the file system. It is interesting to see what you can get from a star import:
I assume this is because some other code already imported those classes explicitly to Python's idea of Star imports are discouraged in Python, and I wonder if they should not simply be an error when the package is a Java one. (Not in 2.7, probably.) |
Are you suggesting a warning in this case that an |
Yes, I would like to make the request. |
Very odd.. Import * Works for me on 2.7.2 (Java21) on Mac, but NOT on Windows....? |
I encountered the issue as below when executing Jython script.
This error happened after Jython 2.7 upgraded to 2.7.2 , so didn't happen with same script on Jython 2.7.
By modifying import * to specify class , this issue was resolved.
Before:
from java.util import *
from java.util import *
from java.io import *
After :
from java.util import Properties
from java.io import FileInputStream
from java.lang import System
Question
Import * seems to fail to work on Jython V2.7.2 . Is this issue due to bug on Jython 2.7.2 ?
The text was updated successfully, but these errors were encountered: