1

I have a Java class that is the entry point for my Fn Function (within an Fn Application) using FDK 1.0.95 that instantiates a Log4j2 Logger.

public class MyClass {

    private final Logger LOG = LogManager.getLogger(this.getClass());

}

I have a testing class that tests a handle method within MyClass that is very basic, looks something like this.

public class MyClassTest {

    @Rule
    public final FnTestingRule testing = FnTestingRule.createDefault();

    @Test
    public void shouldReturnGreeting() {
        testing.givenEvent().enqueue();
        testing.thenRun(InsertSystem.class, "handleRequest");

        FnResult result = testing.getOnlyResult();
        Assert.assertNotNull(result.getBodyAsString());
    }

}

I am using log4j2 version 2.11.2 in my pom.xml.

When running the test in my IntelliJ IDE, it runs without any issues instantiating the logger, but when I run fn --verbose deploy --create-app -all --local in the root of the Fn Application to build and deploy all of the Fn Functions grouped in this application I get the following stack trace.

Caused by: java.lang.IllegalAccessError: class com.sun.org.apache.xerces.internal.parsers.XML11Configuration (in unnamed module @0x3cce5371) cannot access class jdk.xml.internal.JdkXmlUtils (in module java.xml) because module java.xml does not export jdk.xml.internal to unnamed module @0x3cce5371
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.<init>(XML11Configuration.java:537)
    at com.sun.org.apache.xerces.internal.parsers.XIncludeAwareParserConfiguration.<init>(XIncludeAwareParserConfiguration.java:130)
    at com.sun.org.apache.xerces.internal.parsers.XIncludeAwareParserConfiguration.<init>(XIncludeAwareParserConfiguration.java:91)
    at com.sun.org.apache.xerces.internal.parsers.DOMParser.<init>(DOMParser.java:145)
    at com.sun.org.apache.xerces.internal.parsers.DOMParser.<init>(DOMParser.java:129)
    at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.<init>(DocumentBuilderImpl.java:138)
    at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.<init>(DocumentBuilderImpl.java:131)
    at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl.setFeature(DocumentBuilderFactoryImpl.java:210)
    at org.apache.logging.log4j.core.config.xml.XmlConfiguration.enableXInclude(XmlConfiguration.java:238)
    at org.apache.logging.log4j.core.config.xml.XmlConfiguration.newDocumentBuilder(XmlConfiguration.java:197)
    at org.apache.logging.log4j.core.config.xml.XmlConfiguration.<init>(XmlConfiguration.java:92)
    at org.apache.logging.log4j.core.config.xml.XmlConfigurationFactory.getConfiguration(XmlConfigurationFactory.java:46)
    at org.apache.logging.log4j.core.config.ConfigurationFactory$Factory.getConfiguration(ConfigurationFactory.java:454)
    at org.apache.logging.log4j.core.config.ConfigurationFactory$Factory.getConfiguration(ConfigurationFactory.java:386)
    at org.apache.logging.log4j.core.config.ConfigurationFactory.getConfiguration(ConfigurationFactory.java:261)
    at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:616)
    at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:637)
    at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:231)
    at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:153)
    at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:45)
    at org.apache.logging.log4j.LogManager.getContext(LogManager.java:194)
    at org.apache.logging.log4j.LogManager.getLogger(LogManager.java:581)
    at com.MyClass.<init>(MyClass.java:9)
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)

I have tried different versions of both Log4j2 and FDK to no avail.

ealagic
  • 51
  • 1
  • `unnamed module` suggests that your project needs a module-info.java. – VGR May 20 '19 at 04:57
  • So I played around with this a bit more, and the solution I found was to use other forms of configuration outside of the standard XML configuration for Log4j2. I ended up using the JSON configuration approach and the problem went away. – ealagic May 21 '19 at 13:03

0 Answers0