[Biojava-dev] Bug report: getClassLoader() null return not handled

Thomas Down td2 at sanger.ac.uk
Fri May 7 12:13:17 EDT 2004


Thanks for pointing this out.

The same problem actually occurs in quite a lot of places -- quite a 
few areas of the BioJava "guts" do things with ClassLoaders.  I've 
added a little ClassTools utility which provides a safe method for 
getting hold of ClassLoaders.  Should be in CVS soon, or grab 
tommorow's nightly build.

I'd be very interested to hear how you get on with IKVM.  To date, I 
don't know of anyone who's used Biojava with a non-Sun-derived Java 
implementation.

      Thomas.


On 6 May 2004, at 02:26, David Jung wrote:

> Hi.
> I'm new to biojava and just starting to try it out.
> Unfortunetely, I'm unable to use it because a handful of classes
> have static constructors that throw null-pointer exceptions when
> the type is loaded.
>
> For example, code like:
> SymbolList dna = DNATools.createDNA("atcggtcggctta");
>
> (from the cookbook) throws a null-pointer exception.
> I traced the problem to the following lines of code in the 
> AlphabetManager:
>
>      InputStream alphabetStream = 
> AlphabetManager.class.getClassLoader().getResourceAsStream(
>        "org/biojava/bio/symbol/AlphabetManager.xml"
>
> The problem here is that a call is made to getClassLoader() which is 
> then immediately used, without
> checking for a null return value.  According to Sun's JDK1.4.x 
> documentation for the
> Class.getClassLoader() method:
>
> /Returns the class loader for the class. Some implementations may use 
> null to represent the bootstrap class loader. This method will return 
> null in such implementations if this class was loaded by the bootstrap 
> class loader.
> /
> Although when run from the .jar file in Sun's implementation, null 
> isn't returned,
> it would be more portable and correct if the case was tested for.
> I'm trying to run biojava under Linux using the IKVM virtual machine.  
> I've posted
> to their list about the issue but it seems to be valid behaviour for a 
> VM.
> If the return is null, the static method 
> ClassLoader.getSystemClassLoader() should
> be used to get a class loader instead.
> Making this change in AlphabetManager fixed that problem (only for it 
> to get
> to a similar case in RNATools.loadGeneticCode() )
>
> I sould greatly appreciate if you could incorporate the fixes into you 
> next version so
> that I may use biojava.
> Thanks.  (Biojava looks good from my reading of the tutorial/cookbook! 
> btw.)
> -David.
>
>
>
> _______________________________________________
> biojava-dev mailing list
> biojava-dev at biojava.org
> http://biojava.org/mailman/listinfo/biojava-dev



More information about the biojava-dev mailing list