ObjectDB ObjectDB

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


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());
        return l;

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

public class Element extends [] implements []

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

For some reason the error is reported on a subtype:


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:


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

--- Webel IT Australia, "The Elements of the Web", Specialists in model-based UML, SysML, Enterprise Java, XML, and Drupal CMS web engineering. Dr Darren Kelly, BSc, PhD, https://www.webel.com.au

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
ObjectDB - Fast Object Database for Java (JPA/JDO)

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

ObjectDB Support
ObjectDB - Fast Object Database for Java (JPA/JDO)


To post on this website please sign in.