Title: Imports in python from java do not work if there is a package the same name as class
Type: Severity: normal
Components: Core Versions: Jython 2.7
Status: closed Resolution: invalid
Dependencies: Superseder:
Assigned To: Nosy List: EhWhoAmI, adamburke, jeff.allen
Priority: Keywords:

Created on 2018-04-10.22:21:55 by EhWhoAmI, last changed 2019-05-02.06:13:16 by jeff.allen.

msg11887 (view) Author: (EhWhoAmI) Date: 2018-04-10.22:21:53
If I import a java class into jython, then import a class within a package that is the same name of the class, it comes up with a java.lang.NoClassDefFoundError. Only happens in a situation like that. If I don't import that, it does not fail.

Here's an example

Exception in thread "main" Traceback (most recent call last):
  File "<string>", line 1, in <module>
java.lang.NoClassDefFoundError: jythonbug/test (wrong name: jythonbug/Test)
	at java.lang.ClassLoader.defineClass1(Native Method)
	at java.lang.ClassLoader.defineClass(
	at Method)
	at java.lang.ClassLoader.loadClass(
	at sun.misc.Launcher$AppClassLoader.loadClass(
	at java.lang.ClassLoader.loadClass(
	at java.lang.ClassLoader.loadClass(
	at java.lang.Class.forName0(Native Method)
	at java.lang.Class.forName(
	at org.python.core.Py.loadAndInitClass(
	at org.python.core.Py.findClassInternal(
	at org.python.core.Py.findClassEx(
	at org.python.core.packagecache.SysPackageManager.findClass(
	at org.python.core.packagecache.PackageManager.findClass(
	at org.python.core.packagecache.SysPackageManager.findClass(
	at org.python.core.PyJavaPackage.__findattr_ex__(
	at org.python.core.PyObject.__findattr__(
	at org.python.core.PyObject.impAttr(
	at org.python.core.imp.import_next(
	at org.python.core.imp.import_logic(
	at org.python.core.imp.import_module_level(
	at org.python.core.imp.importName(
	at org.python.core.ImportFunction.__call__(
	at org.python.core.PyObject.__call__(
	at org.python.core.__builtin__.__import__(
	at org.python.core.imp.importOne(
	at org.python.pycode._pyx2.f$0(<string>:1)
	at org.python.pycode._pyx2.call_function(<string>)
	at org.python.core.Py.runCode(
	at org.python.core.Py.exec(
	at org.python.util.PythonInterpreter.exec(
	at jythonbug.Jythonbug.main(

java.lang.NoClassDefFoundError: java.lang.NoClassDefFoundError: jythonbug/test (wrong name: jythonbug/Test)

However, when you comment lines 13 and 14 in, the import passes.
msg12392 (view) Author: Adam Burke (adamburke) Date: 2019-03-23.23:44:49
Hi, this may well be an issue, but unfortunately the example code didn't attach.
msg12482 (view) Author: Jeff Allen (jeff.allen) Date: 2019-05-02.06:13:16
We made a change to the way import picks its way amongst Java and Python packages, in aid of #2654, that may be relevant:, it's hard to say without the example. The associated test explores the limits of what is possible at present.

There appear to be some behaviours engrained in import that don't make best sense. In the end, a given name will have to designate just one thing.
Date User Action Args
2019-05-02 06:13:16jeff.allensetstatus: open -> closed
resolution: invalid
messages: + msg12482
nosy: + jeff.allen
2019-03-23 23:44:50adamburkesetnosy: + adamburke
messages: + msg12392
2018-04-10 22:21:55EhWhoAmIcreate