Post-compile enhancement fails when static Log4j 2.5 based logger used in Entity

#1

I doubt this is an ObjectDB-enhancer problem, I am however reporting it in case anybody else encounters the problem too. It is mostly also not a concern for my own web app, because in most cases a non-static logging variable holder can be used in an @Entity.

    ObjectDB 2.6.3_04

    Apache Log4j2 - 2.5

    Mac OS X

    jdk1.7.0_51 or jdk1.8.0_60

    NetBeans 8.1Beta

I created a log4j2 LoggerWrapper using the technique described under the Log4j2 manual: Generating Source Code for a Custom Logger Wrapper (otherwise not shown here, see that link for examples). My LoggerWrapper offers a cache of loggers keyed to classes for lookup:

 public final class LoggerWrapper extends ExtendedLoggerWrapper {

 private static final Map<Class,LoggerWrapper> loggerWrappers = new HashMap<Class,LoggerWrapper>();  

    static public LoggerWrapper findLoggerWrapperFor(Class clazz) {
        if (loggerWrappers.containsKey(clazz)) return loggerWrappers.get(clazz);
        LoggerWrapper l = LoggerWrapper.create(clazz.getName());
        loggerWrappers.put(clazz,l);
        return l;
    }

If I use that in an @Entity for a static logger variable:

@Entity
public class Element extends [] implements []
{

static final private LoggerWrapper LOGGER = LoggerWrapper.findLoggerWrapperFor(Element.class);

For some reason the error is reported on a subtype:

@Entity

public class SubEntity extends Element {

On post-compile enhancement I get this error (as reported in the odb log file):

[ObjectDB 2.6.3_04] Failed to process class file of type 'com.example.SubEntity' (error 422)
com.objectdb.o.UserException: Failed to process class file of type 'com.example.SubEntity'
at com.objectdb.o.MSG.d(MSG.java:75)
at com.objectdb.o.JEL.A(JEL.java:446)
at com.objectdb.o.JEN.m(JEN.java:101)
at com.objectdb.Enhancer.main(Enhancer.java:33)
Caused by: java.lang.LinkageError: loader constraint violation: loader (instance of ) previously initiated loading for a different type with name "org/xml/sax/InputSource"
at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:237)
at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:348)
at org.apache.logging.log4j.core.config.xml.XmlConfiguration.(XmlConfiguration.java:97)

In the build.xml Ant script for the post-compile enhancement the class path is:

javac.classpath:lib/objectdb.jar:/usr/local/java/owner/owner-1.0.9.jar:/usr/local/java/apache-log4j-2.5-bin/log4j-core-2.5.jar:/usr/local/java/apache-log4j-2.5-bin/log4j-api-2.5.jar:/usr/local/java/apache-log4j-2.5-bin/log4j-web-2.5.jar

If I comment out that static LOGGER variable init line, the error vanishes and post-compile enhancement works.

#2

It seems like a class loading conflict.

This will be solved in future Enhancer versions by avoiding class loading during enhancement.

If you have a longer stack trace in the log it may help.

ObjectDB Support
#3

Build 2.6.6_05 should fix the issue. Thank you for this report.

ObjectDB Support

Reply