[aspectwerkz-dev] Sort of a bug in AspectWerkzPreProcessor.java

Niklas Therning <[email protected]> Tue, 07 Dec 2004 13:31:50 +0100
Newsgroups gmane.comp.java.aspectwerkz.devel
Message-ID <[email protected]>
Hi,

I've just started using AspectWerkz and I find it very useful! I'm using 
it in a cocoon-based webapp. My problem is that on each http request I 
get the following (several times) on the console:

AspectWerkz - WARN - Error pre-processing class null in 
Thread[Thread-15,5,main]
java.lang.NullPointerException
        at 
org.codehaus.aspectwerkz.transform.AspectWerkzPreProcessor.preProcess(AspectWerkzPreProcessor.java:131)
        at 
org.codehaus.aspectwerkz.hook.impl.ClassPreProcessorHelper.defineClass0Pre(ClassPreProcessorHelper.java:107)
        at java.lang.ClassLoader.defineClass(ClassLoader.java:539)
        at java.lang.ClassLoader.defineClass(ClassLoader.java:448)
        at 
org.apache.xalan.xsltc.trax.TemplatesImpl$TransletClassLoader.defineClass(TemplatesImpl.java:125)
        at 
org.apache.xalan.xsltc.trax.TemplatesImpl.defineTransletClasses(TemplatesImpl.java:296)
        at 
org.apache.xalan.xsltc.trax.TemplatesImpl.getTransletInstance(TemplatesImpl.java:333)
        at 
org.apache.xalan.xsltc.trax.TemplatesImpl.newTransformer(TemplatesImpl.java:366)
...

The NPE is thrown on this line:

final String className = name.replace('/', '.');

I think it should rather be

final String className = name != null ? name.replace('/', '.') : null;

As I understand it the filter() method, which is called right after the 
line above, will filter out classes with a null name anyway.

I guess it's not really a bug since 
ClassPreProcessorHelper.defineClass0Pre() uses the original byte-array 
if an exception is thrown within AspectWerkzPreProcessor.preProcess(). 
The problem is that since this gets written directly to stderr there's 
no way for me to suppress these error messages and it's rely annoying 
and could even introduce a performance penalty in my application.

Regards,
Niklas Therning