Issue1531644

classification
Title: import * makes java exception uncatchable
Type: Severity: normal
Components: Core Versions:
Milestone:
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: cgroves, nduboc
Priority: normal Keywords:

Created on 2006-07-31.10:29:30 by nduboc, last changed 2006-08-17.22:24:46 by cgroves.

Files
File name Uploaded Description Edit Remove
jython-exceptions.py nduboc, 2006-07-31.10:32:45 Code of the first sample
jython-exceptions2.py nduboc, 2006-07-31.10:33:17 Code of the second sample
Messages
msg1184 (view) Author: Nicolas Duboc (nduboc) Date: 2006-07-31.10:29:30
 I'm investigating an old bug registered against the
Debian package of
Jython :
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=281038

 While searching on the web for similar problems I
found this thread :
  
http://mail.python.org/pipermail/python-list/2004-August/232592.html
I think the root problem may be the same. But it does
not contain any
answer.

 I think I have reduced the problem to a problem with
"import *" :

---------------------------------
import java

java.lang.Class.forName('org.postgresql.Driver')

try:
    con=
java.sql.DriverManager.getConnection('jdbc:postgresql:skdb',
'admin', '')
    # raise an SQLException because I have no postgres
server
except java.sql.SQLException, e:
    print 'Caught SQLException'
    print 'Class:', e.getClass().getName()
    print 'Base class:',
e.getClass().getSuperclass().getName()
else:
    print 'UnCaught'
---------------------------------

On my Debian testing box, with Jython 2.1, the Postgres
java driver and
java1.5.0_06 (Debian package of Sun JDK), this code
prints :

---------------------------------
Caught SQLException
Class: org.postgresql.util.PSQLException
Base class: java.sql.SQLException
---------------------------------

Now consider this code :

---------------------------------
from java.lang import Class
from java.lang import Exception as JavaException

from java.sql import *


Class.forName('org.postgresql.Driver')

try:
    con=
DriverManager.getConnection('jdbc:postgresql:skdb',
'admin', '')
    # raise an SQLException because I have no postgres
server
except SQLException, e:
    print 'Caught SQLException'
    print 'Class:', e.getClass().getName()
    print 'Base class:',
e.getClass().getSuperclass().getName()
except JavaException, e:
    print 'Caught JavaException'
    print 'Class:', e.getClass().getName()
    print 'Base class:',
e.getClass().getSuperclass().getName()
    print 'Base base class:',
e.getClass().getSuperclass().getSuperclass().getName()
else:
    print 'UnCaught'
---------------------------------

it prints :

---------------------------------
Caught JavaException
Class: org.postgresql.util.PSQLException
Base class: java.sql.SQLException
Base base class: java.lang.Exception
---------------------------------

  I know the "import *" is discouraged with Jython. But
I wondered if
this precise limitation is known.
msg1185 (view) Author: Nicolas Duboc (nduboc) Date: 2006-07-31.10:35:05
Logged In: YES 
user_id=756836

The two code snippets are available as attached files.
(Don't know how to make bug tracker preserve indentation.)
msg1186 (view) Author: Charlie Groves (cgroves) Date: 2006-08-05.23:00:01
Logged In: YES 
user_id=1174327

This was a problem with lazily loaded java classes not being
initialized before a subclass check.  Fixed in r2874.
msg1187 (view) Author: Charlie Groves (cgroves) Date: 2006-08-17.22:24:46
Logged In: YES 
user_id=1174327

Copied over to trunk in r2884
History
Date User Action Args
2006-07-31 10:29:30nduboccreate