Issue461151

classification
Title: Simple java class import
Type: Severity: normal
Components: None Versions:
Milestone:
process
Status: closed Resolution: accepted
Dependencies: Superseder:
Assigned To: otmarhumbel Nosy List: cgroves, otmarhumbel, pedronis
Priority: normal Keywords: patch

Created on 2001-09-13.09:04:38 by otmarhumbel, last changed 2007-12-02.22:16:26 by cgroves.

Messages
msg2129 (view) Author: Oti Humbel (otmarhumbel) Date: 2001-09-13.09:04:38
The following lines added just at the beginning of 
method importFromAs in org/python/core/imp.java (from 
the 2.0 codebase) would make the import of single java 
classes a bit more tolerant, especially if the package 
manager encounters a 'bad' .jar File:


public static void importFromAs(String mod, String[] 
names, String[] asnames, PyFrame frame) {
  if ( names.length==1 && names.length==names.length 
&& asnames[0].equals(names[0]) ) {
    // this is a candidate for simple java class import
    String packageName = mod;
    String fullClassName = packageName + "." + names
[0];
    try {
      Class.forName( fullClassName );
      PySystemState.add_package( packageName );
    } catch( Throwable t ) {}
  }
  // rest of method left untouched
  // ...
}

msg2130 (view) Author: Oti Humbel (otmarhumbel) Date: 2002-03-03.10:22:16
Logged In: YES 
user_id=105844

This patch gives a NullPointerException when starting 
Jython 21.
Therefore it needs an embracing if as follows:

	if (names != null  &&  asnames != null) {
		
	}

Oti.
msg2131 (view) Author: Oti Humbel (otmarhumbel) Date: 2002-03-05.17:02:31
Logged In: YES 
user_id=105844

OK, I admit this is a fragile patch. As Samuele said: it is 
an idea to be worked over.
After many tests the following code seems to be stable for 
me in Jython 21 (if I only use java imports of the form: 
from my.package import oneClass). Same place, same method:

  if ( names != null ) {
    if ( names.length == 1 && asnames == null ) {
      // this is a candidate for simple java class import
      String packageName = mod;
      String fullClassName = packageName + "." + names[0];
      try {
        Class.forName( fullClassName );
        PySystemState.add_package( packageName );
      } catch( Throwable t ) {}
    }
  }

Please apologize for the confusion!
Best wishes,
Oti.
msg2132 (view) Author: Samuele Pedroni (pedronis) Date: 2002-03-18.14:59:49
Logged In: YES 
user_id=61408


It could be in the wrong place, it should be probably
implemented at PackageManager level or just the 
level above. You should consider that the semantics
python imports take over java imports should be preserved,
and that you don't want to load classes that should
not really be loaded, because of side effects of
static initiliazers.
msg2133 (view) Author: Samuele Pedroni (pedronis) Date: 2005-01-09.19:21:36
Logged In: YES 
user_id=61408

we want the functionality, the the placing is indeed not ideal.
But indeed with new importing with want the feature that
indipendently of scanning if a classloader is made
accessible we want to be able to load classes from it no
matter what.
msg2134 (view) Author: Charlie Groves (cgroves) Date: 2007-12-02.22:16:26
Looks like this was done in JavaImportHelper.
History
Date User Action Args
2001-09-13 09:04:38otmarhumbelcreate