[Biojava-l] null pointer exception

Chun-Nuan Chen chun@bioweircom.org
Fri, 10 May 2002 08:33:37 -0700


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
>