You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by Michael Taylor <mt...@emeraldcave.net> on 2000/07/12 09:45:00 UTC

compiler problem causes IllegalAccessError bugs in current distribution of Xalan_1_1

I am sure this has already been reported, but I have just joined this list and
xml.apache.org wouldn't give me an email address or access to a defect tracking
system to submit this.  If this is the wrong forum, please tell me and accept
my humble appologies.

I have seen others struggling with this issue while searching the net for a
resolution and I wanted to let you know what the issue is and a workaround

This is not a bug in Xalan, however, it is a defect introduced by the compiler
used by ANT into the build for Xalan 1_1.

When some compilers generate bytecodes for .class references (such as
BSFManager.class), they create a field and cache the result of a Class.forName
lookup.  This is done by creating a static field with package access
restrictions.  

In the case of references to com.ibm.bsf.BSFManager class, you get code
equivalent to having declared :

Class class$com$ibm$bsf$BSFManager;

Now, if you refer to BSFManager.class in six places, only the one copy is used.
 The problem occurs when inheritance is used *accross* package boundaries.  As
I mention, this is package security level.  Now, it's invisible to subclasses
in other packages but the compiler fails to detect this.  If you have two
classes in different packages where one inherits from the other, you will get
only one field for the class.  When the subclass in the other package attempts
to access you get an illegal access error because the compiler has generated
invalid bytecode.

Specifically, I encountered this issue for
org.apache.xalan.xpath.ExtensionFunctionHandler and
org.apache.xalan.xslt.ExtensionNSHandler.  These two classes both use
BSFManager.class, and ExtensionNSHandler will always fail.  This actually
occurs in startupComponent(xx) but the location is really irrelevant.

There are several workarounds:
1.  Choose a compiler that works
2.  Write your own code instead of using the '.class' compiler hack (err,
language feature I mean)
3.  Declare the field yourself and make it public or protected so that all
subclasses will see it.

I don't know how ANT works or what compiler it uses, so I chose the third
option.

I added the following declaration to ExtensionFunctionHandler:

public static Class class$com$ibm$bsf$BSFManager;

This solved the problem for this one case, but others are lurking.

So, what is the general solution?  You tell me.  I need to know what compiler
ANT will use for Xalan.  I assume it's using the JAVAC compiler from the
JDK1.2.2 that I have in my path.  I have only previously seen this issue with
Symantec's compiler, and that's when we stopped using it.

Please provide any information you can so that I can get a good clean build
without worrying about further access errors down the road.

--  
Michael Taylor, mtaylor@emeraldcave.net