You are viewing a plain text version of this content. The canonical link for it is here.
Posted to general@xml.apache.org by Jo...@lotus.com on 2001/10/19 22:54:07 UTC

XML-Commons and JDK 1.1 compatability

We've got a little problem in org.apache.xalan.xslt.FactoryFinder.

As currently checked in, the code won't compile under JDK 1.1.8; there's a
hard dependency on the getContextClassLoader() method, which isn't present
before JDK 1.2. We've seen that problem before, and in the past our
solution was to use reflection to move the dependency from compile time  to
run time. Here's a quick-and-dirty version of that:

  static class ClassLoaderFinderConcrete extends ClassLoaderFinder {

    static final Class[] noparms=new Class[0];
    static final Object[] noargs=new Object[0];

    ClassLoader getContextClassLoader() {
      // The following line will not compile under JDK 1.1,
      // due to the hard dependency on a 1.2-and-later method:
      //     return Thread.currentThread().getContextClassLoader();
      // Hence we use reflection to move the dependency from
      // compile-time to run-time.

      Thread ct=Thread.currentThread();
      ClassLoader cl=null;
      try
      {
     java.lang.reflect.Method gccl
       =ct.getClass().getMethod("getContextClassLoader",noparms);
     cl=(ClassLoader)(gccl.invoke(ct,noargs));
      }
      catch(Exception e)
      {
     throw new LinkageError();
      }

      return cl;
    }
  }

Unfortunately, we then run into a second problem. The fallback in the
caller, if the context classloader can't be resolved, is to return the same
classloader that loaded the FactoryFinder object. But in JDK 1.1.x that
method is documented as potentially returning null for any class brought in
through the default loader... which isn't exactly a useful response for
those who actually want to load classes.

I seem to remember dealing with this last tim around and finding a fallback
for the fallback -- some way to retrieve the default classloader object --
but I honestly don't remember what it was. Does anyone out there have a
clue?


Until both issues are fixed, I don't think we'll either compile or run
reliably under JDK1.1. And I don't believe we've yet reached consensus that
the JDK1.1 users can be abandoned.


-------------------------------------------

Related problem: org\xml\sax\helpers\parserAdapter wass using the JDK 1.2
Collections methods add() and get() on a Vector. That too won't compile
under JDK 1.1.x; it must be changed (trivially) to use addElement() and
elementAt(). I'm going to just go ahead and check that one in, since it
should be harmless. If this glitch is something we acquired from the SAX
team, we should feed this back to them as a suggestion.


---------------------------------------------------------------------
In case of troubles, e-mail:     webmaster@xml.apache.org
To unsubscribe, e-mail:          general-unsubscribe@xml.apache.org
For additional commands, e-mail: general-help@xml.apache.org


Re: XML-Commons and JDK 1.1 compatability

Posted by Edwin Goei <ed...@sun.com>.
Joseph_Kesselman@lotus.com wrote:
> 
> We've got a little problem in org.apache.xalan.xslt.FactoryFinder.
> 
> As currently checked in, the code won't compile under JDK 1.1.8; there's a
> hard dependency on the getContextClassLoader() method, which isn't present
> before JDK 1.2. We've seen that problem before, and in the past our
> solution was to use reflection to move the dependency from compile time  to
> run time. Here's a quick-and-dirty version of that:

I belive that code was copied from xml-commons to the xalan tree
recently.  Shane can probably give more info.  You are correct, the code
will not _compile_ under JDK 1.1.x because of the reason you cite. 
However, it was specificially designed to _run_ on both JDK 1.1.x and
Java 2 VMs.  In particular, it runs in both IE5 and NS4.7 native VMs and
so runs in applets.  The code also works correctly when included as part
of a Java 2 core library which is loaded by the bootstrap classloader.

> [snip]
> 
> Until both issues are fixed, I don't think we'll either compile or run
> reliably under JDK1.1. And I don't believe we've yet reached consensus that
> the JDK1.1 users can be abandoned.

The code still runs on JDK 1.1.x systems so I do not think we are
abandoning those users.  How important is being able to compile on JDK
1.1.x to you?  IMO being able to run in 1.1.x is enough.

> -------------------------------------------
> 
> Related problem: org\xml\sax\helpers\parserAdapter wass using the JDK 1.2
> Collections methods add() and get() on a Vector. That too won't compile
> under JDK 1.1.x; it must be changed (trivially) to use addElement() and
> elementAt(). I'm going to just go ahead and check that one in, since it
> should be harmless. If this glitch is something we acquired from the SAX
> team, we should feed this back to them as a suggestion.

I believe this is fixed in the latest sax2r2-pre2 release.  This bug
affects being able to _run_ in JDK 1.1.x also.

-Edwin

---------------------------------------------------------------------
In case of troubles, e-mail:     webmaster@xml.apache.org
To unsubscribe, e-mail:          general-unsubscribe@xml.apache.org
For additional commands, e-mail: general-help@xml.apache.org