[Biojava-l] null pointer exception

Wayne Volkmuth volkmuth@renovis.com
Fri, 10 May 2002 10:39:03 -0700


Thanks, Chun-Nuan.  I think that throwing a BioError with a more
specific message by checking for a null return from the getClassLoader
call is a good idea, so I like your original proposal.  I agree though
it would be better not to load the xml file off the filesystem.

Wayne

-----Original Message-----
From: Chun-Nuan Chen [mailto:chun@bioweircom.org] 
Sent: Friday, May 10, 2002 9:53 AM
To: biojava-l@biojava.org
Cc: Wayne Volkmuth
Subject: Re: [Biojava-l] null pointer exception

I did a little bit more testing and found the following:


1. There are a few classloaders implemented byTomcat and it will NOT 
allow access to "Common" classloader and any classloaders at 
deeper/higher levels. This "Common" classloader is used to load classes 
under TOMCAT_HOME/common/lib. I have accidentally put the symbolic link 
to biojava.jar  under TOMCAT_HOME/common/lib and that's why I also got 
the NullPointerException previously.

2. Now I moved those biojava-related jar files either to TOMCAT_HOME/lib

(which uses the "SHARE" classloader) OR  
TOMCAT_HOME/webapps/examples/WEB_INF/lib (I created this lib 
subdirectory, which uses the WebappX classloader for each application), 
then I **was able to get hold of the classloader and the servlet worked 
fine.


So, to solve the problem reported by Wayne earlier, we should put the 
biojava related jar files under either 
TOMCAT_HOME/webapps/examples/WEB_INF/lib (you should substitute 
"examples" for the web application you use) or TOMCAT_HOME/lib, and 
restart Tomcat. No changes to AlphabetManager.java will be necessary.


Pls let me know if above approach doesn't work for you.

Thanks,

Chun-Nuan






Chun-Nuan Chen wrote:

> Hi,
>
> The reason you got the NullPointerException is that the following 
> method in class AlphabetManager returns null:
>
> AlphabetManager.class.getClassLoader()
>
> The reason for it to return null is due to the security measures taken

> by the tomcat servlet container. Allow users to access the classloader

> will impose serious security problems on Tomcat.
>
> A possible workaround is to modify AlphabetManager.java to read the 
> AlphabetManager.xml file directly from the file system if the 
> classloader cannot be obtained:
> ....
> 753 ambiguitySymbols.put(new HashSet(), gapSymbol);
> 754 try {
> 755 InputStream alphabetStream=null;
> 756 File f = null;
> 757 FileInputStream fis = null;
> 758 InputSource is =null;
> 759 if(AlphabetManager.class.getClassLoader()==null)
> 760 {
> 761 //System.out.println("the classloader is null");
> 762 f=new File("/tmp/AlphabetManager.xml");
> 763 fis =new FileInputStream(f);
> 764 }
> 765 else
> 766 {
> 767 // System.out.println("the classloader is not null");
> 768 alphabetStream = 
> AlphabetManager.class.getClassLoader().getResourceAsStream(
> 769 "org/biojava/bio/symbol/AlphabetManager.xml");
> 770 if (alphabetStream == null)
> 771 {
> 772 throw new BioError("Couldn't locate AlphabetManager.xml. Badly 
> built biojava archive?");
> 773 }
> 774 }
> 775 if(fis!=null)
> 776 {
> 777 is = new InputSource(fis);
> 778 //System.out.println("inside if: is ="+is);
> 779 }
> 780 else
> 781 {
> 782 is=new InputSource(alphabetStream);
> 783 //System.out.println("inside else: is ="+is);
> 784 }
> 785 DocumentBuilder parser = 
> DocumentBuilderFactory.newInstance().newDocumentBuilder();
> ...
>
> With above change and after re-building the source tree (I had a 
> symbolic link for biojava.jar under the commmon/lib subdirectory of 
> Tomcat, so I don't need to copy this jar over) and restarting Tomcat, 
> I was able to run your servlet with Tomcat 4.0.3 on Redhat 7.3 without

> causing any server error and got something like the following in the 
> browser:
>
> >bug aattagccgt
>
> Pls let me know if this is not the expected result.
>
> Regards,
>
> Chun-Nuan
>
>
>
>
> Wayne Volkmuth wrote:
>
>> I ran across a null pointer exception in AlphabetManager called from 
>> a servlet in tomcat 4.0.3. I posted a bug report, here's the URL :
>>
>> http://www.biojava.org/biojava-bugs/incoming?id=14;page=1;user=guest
>>
>> I stripped down the servlet to the bare minimum, so hopefully that 
>> helps a bit.
>>
>> Thanks
>>
>> Wayne
>>
>
>
>
> _______________________________________________
> Biojava-l mailing list  -  Biojava-l@biojava.org
> http://biojava.org/mailman/listinfo/biojava-l