Issue1674537

classification
Title: Bogus import fails silently
Type: Severity: normal
Components: Jythonc compiler Versions:
Milestone:
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: Nosy List: cgroves, fwierzbicki, hohonuuli, musically_ut
Priority: normal Keywords:

Created on 2007-03-06.00:52:08 by hohonuuli, last changed 2009-03-14.02:06:52 by fwierzbicki.

Messages
msg1530 (view) Author: Brian Schlining (hohonuuli) Date: 2007-03-06.00:52:08
ENVIRONMENT: Jython 2.2b1 on java1.5.0_07 (JIT: null) on Mac OS X 10.4.8

When jython encounters a incorrectly named imported java class it fails silently; Here's an example. Below is it the imports of my jython module and the first funciton in the module. The line 'from org.mbari.vcr import Timecode' is bogus; it should be 'from org.mbari.movie import Timecode'. The jython class is created up to the bogus line


# Start module - mbari.eitsdb
import exceptions
import mbari.aveddb
from org.mbari.vars.annotation.model import Association
from org.mbari.vars.annotation.model import CameraData
from org.mbari.vars.annotation.model import CameraPlatformDeployment
from org.mbari.vars.annotation.model import Observation
from org.mbari.vars.annotation.model import PhysicalData
from org.mbari.vars.annotation.model import VideoArchive
from org.mbari.vars.annotation.model import VideoArchiveSet
from org.mbari.vars.annotation.model import VideoFrame
from org.mbari.vars.annotation.model.dao import VideoArchiveDAO
from org.mbari.vars.annotation.model.dao import VideoArchiveSetDAO
from org.mbari.vcr import Timecode # <-- MISNAMED IMPORT
from org.slf4j import Logger
from org.slf4j import LoggerFactory

def importEvents(url, frameRate):
    pass

This is the result of trying to load the module:

>>> import mbari.eitsdb
>>> dir(mbari.eitsdb)

['Association', 'CameraData', 'CameraPlatformDeployment', 'Observation', 'PhysicalData', 'VideoArchive', 'VideoArchiveDAO', 'VideoArchiveSet', 'VideoArchiveSetDAO', 'VideoFrame', '__doc__', '__file__', '__name__', 'exceptions', 'mbari']

>>> mbari.eitsdb.importEvents(url, frameRate)

AttributeError: module 'mbari.eitsdb' has no attribute 'importEvents'

So Jython is loading the module up to the point that it encounters a bad import, but it fails silently so it appears the module loaded fine, until I try to access a method that is in the module after the bogus line. 
msg1531 (view) Author: Utkarsh Upadhyay (musically_ut) Date: 2007-07-01.07:30:21
I am using jython 2.2rc1, and I think that the problem is not located only in jythonc, which is soon to be deprecated.

My test code:

Base.java:
###Code Begins:
public class Base
{
	public String hello(String s){
		return "Hello "+s;
}
}
###Code Ends.

Sub.py:
###Code Beings:
import Base
class Sub(Base):
	def hi(self,s):
		"@seg public String hi(String s1)"
		return 'Hi '+s;
###Code Ends

App.java:
###Code begind:
public class App{
public static void main(String [] args){
    Sub sub=new Sub();
    String response=sub.hi("Utk");
    System.out.println(response);
}
}
###Code ends

Now, when I use "jythonc Sub.py" (without compiling Base.java to Base.class)
I get this:

###

Creating .java files:
  Sub module

Compiling .java to .class...
Compiling with args: ['/opt/sun-jdk-1.6.0.01/bin/javac', '-classpath', '/home/utkarsh/Jython/jython2.2rc1/jython.jar:.:./jpywork::/home/utkarsh/Jython/jython2.2rc1/Tools/jythonc:/home/utkarsh/Jython/jython2.2rc1/Lib:__classpath__', './jpywork/Sub.java']
0  

###

Now, the Sub.class file is generated in the ./jpywork folder, not in the currect directory. Compiling App.java yeilds this error message:

###
App.java:3: cannot find symbol
symbol  : class Sub
location: class App
Sub sub=new Sub();
^
###
After copying the Sub.class file from the ./jpyworks directory, this error:

###
App.java:4: cannot find symbol
symbol  : method hi(java.lang.String)
location: class Sub
String response=sub.hi("Greetings");
                   ^
###

Hence, the Sub.java file was smoorhtly created wothout any reference to the Base.java file, a bug, in my opinion.

However, if I try importing Sub.py in jython 2.2rc1, I get this encouraging message:

>>> import Sub
Traceback (innermost last):
  File "<console>", line 1, in ?
  File "/home/utkarsh/Jython/TestingCode/Sub.py", line 1, in ?
ImportError: no module named Base
>>> 

On jython2.2b1, the import went smoothly, which was the initial bug itself.

After compiling the Base.java to Base.class, and then running "jythonc Sub.py", I get this (among other irrelevent lines):

###
Creating .java files:
  Sub module
    Sub extends Base                           <<<<<<< NOTE THIS LINE

Compiling .java to .class...
Compiling with args: ['/opt/sun-jdk-1.6.0.01/bin/javac', '-classpath', '/home/utkarsh/Jython/jython2.2rc1/jython.jar:.:./jpywork::/home/utkarsh/Jython/jython2.2rc1/Tools/jythonc:/home/utkarsh/Jython/jython2.2rc1/Lib:__classpath__', './jpywork/Sub.java']
0  
###

There has been significant change in the ~/src/org/python/core/JavaImportHelper.java, 

Hence afterwards, everything works fine, both in App.java and after "import Sub.py". (The Sub.class file made by jythonc is still made in ./jpyworks)

I think that this bug should be completely corrected if we resort to the JythonFactory method of extending code.

So can this bug be closed now?

~~
musically_ut
msg1532 (view) Author: Charlie Groves (cgroves) Date: 2007-07-07.23:14:03
Since this is just jythonc, I moved it to the jythonc group.  I'm planning on closing all of those out once we finish up a replacement for jythonc.
msg1533 (view) Author: Utkarsh Upadhyay (musically_ut) Date: 2007-07-08.03:03:53
Sounds fair enough.

~~musically_ut
msg4282 (view) Author: Frank Wierzbicki (fwierzbicki) Date: 2009-03-14.02:06:52
jythonc is no longer maintained.
History
Date User Action Args
2009-03-14 02:06:52fwierzbickisetstatus: open -> closed
nosy: + fwierzbicki
resolution: wont fix
messages: + msg4282
2007-03-06 00:52:08hohonuulicreate