Skip to content

Commit c0fdb53

Browse files
committed
avoid native-image analysis running into java imports
1 parent 870c79b commit c0fdb53

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

graalpython/lib-graalpython/java.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,20 +43,25 @@
4343
class JavaPackageLoader:
4444
@staticmethod
4545
def is_java_package(name):
46-
return any(p.getName().startswith(name) for p in type("java.lang.Package").getPackages())
46+
try:
47+
package = type("java.lang.Package")
48+
return any(p.getName().startswith(name) for p in package.getPackages())
49+
except KeyError:
50+
return False
4751

4852
@staticmethod
4953
def _make_getattr(modname):
5054
modname = modname + "."
5155
def __getattr__(key, default=None):
52-
loadname = modname + key
53-
if JavaPackageLoader.is_java_package(loadname):
54-
return JavaPackageLoader._create_module(loadname)
55-
else:
56-
try:
57-
return type(modname + key)
58-
except KeyError:
59-
raise AttributeError(key)
56+
if sys.graal_python_host_import_enabled:
57+
loadname = modname + key
58+
if JavaPackageLoader.is_java_package(loadname):
59+
return JavaPackageLoader._create_module(loadname)
60+
else:
61+
try:
62+
return type(modname + key)
63+
except KeyError:
64+
raise AttributeError(key)
6065
return __getattr__
6166

6267
@staticmethod

0 commit comments

Comments
 (0)