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
from java.util import * not working in 2.7.2 jdk 14 #105
Comments
also, this error does not occur when using jdk 1.8. |
after calling from java import * and then calling the object and from import java.util import *, it works. Can this be resolved by patching JavaImportHelper.java? Jython 2.7.2 (v2.7.2:925a3cc3b49d, Mar 21 2020, 10:03:58)
|
Import is a mess. I wrote these notes trying to understand it.
Could be. There is a test for star import. I wonder if we skip it on 9 or why it doesn't catch the problem?
In that case, I think we have the introduction of Java modules at Java 9 to blame. I recall it was necessary to enumerate by hand what would get indexed, and so it gets distinct treatment. Ah yes, here is the last place I worked on that, which might be worth a look:
You can see where I've worked on this problem, but evidently not nailed it in : ffffe7b . Also, my commit titles need to be slightly shorter :) |
Hi Jeff - yeah, I saw the import_star_from _java.py test. It fails, so I figured you guys knew about it! $ jython dist/Lib/test/import_star_from_java.py Blame it on jigsaw! Will fiddle around with SysPackageManager.java. Thanks! |
(Edited by Jeff to make the code display.) OK, mystery solved!
inside the for loop essentially wipes out the class list whenever
in the jython registry. The class list returned from jrt:/java.base looks like this:
The "@" character precedes all the other classes - so the substring method return an empty string. The jython ships with this set to true by default and changing this setting to false crashes jython. Commenting out the 4 lines above solves the problem and doesn't seem to produce any errors. But using my hack in production makes me nervous. Do you think commenting out those lines will be safe? What are your thoughts on how this should be handled? Let me know if I can help. woohoo!
FYI - jython crashes with this error when respectJavaAccessibility=false
|
I noticed today that this is not an issue in Java 11. So sometime between Java 11 and 14, a bunch of modules got marked as protected. |
I think something has changed to be more strict about We should not depend on non-public "API" but in a few places we do. I'm not surprised it is the posix module giving us this problem. (It may even be in jnr.posix, not our code at all.) Exploring the original complaint:
I think you have found that the import (or the caching) gets quietly abandoned part way through, leaving us an incomplete cache for packages where it happens. |
OK, did some more poking around... The code segment that looks for the "@" and excludes everything after it, is no longer correct with jigsaw becoming enabled by default. In Java 9 and apparently at least through 11, jigsaw was disabled for compatibility. But going forward, that "@" character is always going to be in the beginning of the class list because the core jdk se is a module and the @ denotes module. One way to solve this problem without code change would be to set: python.security.respectJavaAccessibility = false in the jython registry and then run the jvm with an add-opens parameter: --add-opens java.base/java.lang.constant=ALL-UNNAMED this will solve the problem without code change. But this does not resolve the issue of using the @ character to cache java.base module packages. We could remove the @ substring lines of code, but how can we test to make sure this doesn't break something else? Another idea - has anyone tried modularizing jython with module-info.java? Theoretically, we could specify all the java.base packages in module-info.java. see console output below... $ java --add-opens java.base/java.lang.constant=ALL-UNNAMED -jar /usr/jython/jython.jar
|
one more thing... using add-opens method creates a illegal reflective access operations that will be denied in JDK 17. Just to import java.util.HashMap requires this to avoid all the illegal operations: $ java --add-opens java.base/java.lang.constant=ALL-UNNAMED --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.nio=ALL-UNNAMED --add-opens java.base/java.nio.charset=ALL-UNNAMED --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.base/java.util.function=ALL-UNNAMED --add-opens java.base/java.security=ALL-UNNAMED --add-opens java.base/java.io=ALL-UNNAMED -jar /usr/jython/jython.jar so setting python.security.respectJavaAccessibility = false is probably not the way to go. |
import of * from java.lang is also not working in JDK17 |
I can reproduce all this with my installed 2.7.2, but not with the development tip 2.7.3a1, even after deleting and re-creating the cache with the later Java.
This is a Good Thing, and it's tempting to close this immediately, but I'm not conscious what change fixed it. The code @lsgroup identifies is the same. However, I think the problem was never there exactly, but in the position of the There are not many files in |
There are no changes at all within I find that the problem was fixed by upgrading ASM to 9.3 in 7c11f58 . If I revert just that commit on the development tip, and make a clean build, the problem is back.
The content for the cache string is collected here: jython/src/org/python/core/packagecache/CachedJarsPackageManager.java Lines 600 to 608 in 8c3734d
We use ASM in checkAccess to read the access mask from the class and a failure gets treated silently as private .
|
Hi - for some reason, import * does not work for java.util package. It works for other packages.
after import * on java.util, instantiating a class gets NameError. See below:
Jython 2.7.2 (v2.7.2:925a3cc3b49d, Mar 21 2020, 10:03:58)
[Java HotSpot(TM) 64-Bit Server VM (Oracle Corporation)] on java14.0.2
Type "help", "copyright", "credits" or "license" for more information.
Anyone else have this issue?
The text was updated successfully, but these errors were encountered: