problem with log4j2

The public knowledge pool and discussion forum of the OWS community. Do not post confidential information here!
KlausFriese
Posts: 6
Joined: 19 Jul 2021, 10:33

problem with log4j2

Post by KlausFriese »

Hi,

We upgraded the logging in our application from log4j 1.x to the newest 2.17.1 version and now we get errors with OpenWebstart.

Exception is below - log4j-core-2.17.1.jar and log4j-api-2.17.1.jar are in the jnlp and they are loaded. PluginAliases is part of the core-jar. Is this a known problem with OpenWebstart or AdoptOpenJDK? Old webstart is working fine?

Code: Select all

Exiting Boot.mainWithReturnCode() with 0
    ... 27 more 
    at net.sourceforge.jnlp.runtime.classloader.JNLPClassLoader.loadClass(JNLPClassLoader.java:1446) 
    at java.util.Optional.orElseThrow(Optional.java:290) 
    at net.sourceforge.jnlp.runtime.classloader.JNLPClassLoader.lambda$loadClass$9(JNLPClassLoader.java:1446) 
Caused by: java.lang.ClassNotFoundException: org.apache.logging.log4j.core.config.plugins.PluginAliases 
    at net.sourceforge.jnlp.Launcher$TgThread.run(Launcher.java:659) 
    at net.sourceforge.jnlp.Launcher.access$200(Launcher.java:71) 
    at net.sourceforge.jnlp.Launcher.launchApplication(Launcher.java:406) 
    at java.lang.reflect.Method.invoke(Method.java:498) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at dataplan.client.journaldesigner.jd.<clinit>(jd.java:73) 
    at dataplan.common.utilities.dpLogfile.<clinit>(dpLogfile.java:84) 
    at org.apache.logging.log4j.LogManager.getLogger(LogManager.java:666) 
    at org.apache.logging.log4j.LogManager.getContext(LogManager.java:176) 
    at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:47) 
    at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:270) 
    at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:716) 
    at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:695) 
    at org.apache.logging.log4j.core.config.ConfigurationFactory.getConfiguration(ConfigurationFactory.java:323) 
    at org.apache.logging.log4j.core.config.ConfigurationFactory$Factory.getConfiguration(ConfigurationFactory.java:481) 
    at org.apache.logging.log4j.core.config.ConfigurationFactory$Factory.getConfiguration(ConfigurationFactory.java:557) 
    at org.apache.logging.log4j.core.config.xml.XmlConfigurationFactory.getConfiguration(XmlConfigurationFactory.java:46) 
    at org.apache.logging.log4j.core.config.xml.XmlConfiguration.<init>(XmlConfiguration.java:138) 
    at org.apache.logging.log4j.core.config.AbstractConfiguration.initializeWatchers(AbstractConfiguration.java:264) 
    at org.apache.logging.log4j.core.config.AbstractConfiguration.monitorSource(AbstractConfiguration.java:276) 
    at org.apache.logging.log4j.core.util.WatcherFactory.getInstance(WatcherFactory.java:55) 
    at org.apache.logging.log4j.core.util.WatcherFactory.<init>(WatcherFactory.java:47) 
    at org.apache.logging.log4j.core.config.plugins.util.PluginManager.collectPlugins(PluginManager.java:152) 
    at org.apache.logging.log4j.core.config.plugins.util.PluginRegistry.loadFromPackage(PluginRegistry.java:246) 
Caused by: java.lang.NoClassDefFoundError: org/apache/logging/log4j/core/config/plugins/PluginAliases 
    at net.sourceforge.jnlp.Launcher$TgThread.run(Launcher.java:679)

Stephan Classen
Posts: 224
Joined: 27 Mar 2020, 09:55

Re: problem with log4j2

Post by Stephan Classen »

We have heard of others with similar problems.
It would be really great if you could create a minimal reproducer application such that we can debug this issue and fix it.

Janak Mulani
Posts: 497
Joined: 24 Mar 2020, 13:37

Re: problem with log4j2

Post by Janak Mulani »

I created a minimal sample which works with OWS.

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<jnlp
    spec="1.0+"
    codebase="http://localhost:8080/jnlp">
  <information>
          <title>Log4J</title>
          <vendor>Karakun AG</vendor>
          <offline-allowed/>
      </information>
  <security>
     <all-permissions/>
  </security>
  <resources>
    <j2se version="1.8*"/>
    <jar href="generated-jars/logforj.jar"/>
    <jar href="jars/s_log4j-core-2.17.1.jar"/>
    <jar href="jars/s_log4j-api-2.17.1.jar"/>
  </resources>
  <application-desc main-class="LogForJExample">
  </application-desc>
</jnlp>

Code: Select all

public class LogForJExample {

	private static final Logger LOG = LogManager.getLogger(LogForJExample.class);

	public static void main(String[] args) {

		LOG.debug("This Will Be Printed On Debug");
		LOG.info("This Will Be Printed On Info");
		LOG.warn("This Will Be Printed On Warn");
		LOG.error("This Will Be Printed On Error");
		LOG.fatal("This Will Be Printed On Fatal");

		LOG.info("Appending string: {}.", "Hello, World");
	}
}
Could it be that you have old and new versions of Log4J classes in the jars that you are specifying in your Jnlp file?

Stephan Classen
Posts: 224
Joined: 27 Mar 2020, 09:55

Re: problem with log4j2

Post by Stephan Classen »

Janak, I suspect the log4j config has an influence on which classes log4j is loading (and maybe even how it is loading them).

Janak Mulani
Posts: 497
Joined: 24 Mar 2020, 13:37

Re: problem with log4j2

Post by Janak Mulani »

Exception is below - log4j-core-2.17.1.jar and log4j-api-2.17.1.jar are in the jnlp and they are loaded. PluginAliases is part of the core-jar. Is this a known problem with OpenWebstart or AdoptOpenJDK? Old webstart is working fine?
Can you please provide your Log4j2 config file or better still take the sample above and tweak it to reproduce your issue?

Here is how my config looks for the working sample above:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
    <Properties>
        <Property name="basePath">../Log4j2Example/logs</Property>
    </Properties>
    <Appenders>
        <!-- File Appender -->
        <File name="FILE" fileName="${basePath}/logfile.log" append="true">
            <PatternLayout pattern="%-5p | %d{yyyy-MM-dd HH:mm:ss} | [%t] %C{2} (%F:%L) - %m%n" />
        </File>
        <!-- Console Appender -->
        <Console name="STDOUT" target="SYSTEM_OUT">
            <PatternLayout pattern="%-5p | %d{yyyy-MM-dd HH:mm:ss} | [%t] %C{2} (%F:%L) - %m%n" />
        </Console>
    </Appenders>
    <Loggers>
        <Logger name="com.jcg" level="debug" />
        <Root level="info">
            <AppenderRef ref="STDOUT" />
            <AppenderRef ref="FILE" />
        </Root>
    </Loggers>
</Configuration>
Thanks

KlausFriese
Posts: 6
Joined: 19 Jul 2021, 10:33

Re: problem with log4j2

Post by KlausFriese »

Hi and sorry for the delayed answer
Janak Mulani wrote: 27 Jan 2022, 17:03 .....
Could it be that you have old and new versions of Log4J classes in the jars that you are specifying in your Jnlp file?
Don't think so - I had a look in all the cached jar files and I found only the new log4j version in the jars

Janak Mulani wrote: 28 Jan 2022, 06:29 ...
Can you please provide your Log4j2 config file or better still take the sample above and tweak it to reproduce your issue?
...
This is my log4j2.xml:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<!-- Log4j2 configuration for JournalDesigner -->
<Configuration status="debug" monitorInterval="60" packages="dataplan.common.utilities">
  <Appenders>
    <dpAppender name="dpAppender" />
    <Console name="CONSOLE" target="SYSTEM_OUT">
      <PatternLayout pattern="%d %-5p [%t] - %m%n"/>
    </Console>
    <File name="logfile" 
				fileName="${sys:user.home}/JournalDesignerData/jd.log"
    >
      <PatternLayout>
        <Pattern>%d{yyyy-MM-dd HH:mm:ss,SSS} %-5p [%-11t] - %m%n</Pattern>
      </PatternLayout>
    </File>
    <Async name="ASYNC">
      <AppenderRef ref="logfile"/>
      <AppenderRef ref="CONSOLE"/>
    </Async>
  </Appenders>
  <Loggers>
    <Root level="info">
      <AppenderRef ref="ASYNC"/>
      <AppenderRef ref="dpAppender"/>
    </Root>
    <Logger name="org.springframework.core" level="error"/>
    <Logger name="org.springframework.beans" level="error"/>
    <Logger name="org.springframework.context" level="error"/>
    <Logger name="org.springframework.web" level="error"/>
    <Logger name="org.springframework.security" level="error"/>
    <Logger name="org.apache.axis2.util.JavaUtils" level="error"/>
  </Loggers>
</Configuration>
I will test different configurations now, maybe Stephan Classen is right with his idea.

Janak Mulani
Posts: 497
Joined: 24 Mar 2020, 13:37

Re: problem with log4j2

Post by Janak Mulani »

I ran the simple example with the config you provided without any problem.

Can you please modify the example program to reproduce the issue? For instance by using the feature of log4J that uses the PluginAliases class.

Thanks

Janak Mulani
Posts: 497
Joined: 24 Mar 2020, 13:37

Re: problem with log4j2

Post by Janak Mulani »

I tested with another program that tests if a class is on the classpath:

ClassOnPath.png
ClassOnPath.png (24.17 KiB) Viewed 1806 times
Which version of AdoptOpen are you using to run your Jnlp app?

Please provide a snippet and configuration which reproduces your issue.

hilalkale
Posts: 16
Joined: 09 Mar 2022, 09:23

Re: problem with log4j2

Post by hilalkale »

Hi all,

We have the similar problems after updating the log4j to 2.17.2.

OWS: 1.5.2
JDK: Oracle 1.8.0_301

I got PluginAliases error.

If I try running with:

JDK: IBM Semeru Runtime Open Edition 11.0.12.0 or AdoptOpenJDK 11.0.1

I got an "IllegalStateException: zip file closed" error.

But if I switch to OWS3.0.0-alpha2 none of these problems occur and works very well. But as mentioned in another thread, alpha2 in not maintained and will not be released. So how can we solve these problems in 1.5.2?

Janak Mulani
Posts: 497
Joined: 24 Mar 2020, 13:37

Re: problem with log4j2

Post by Janak Mulani »

As stated above, I could not reproduce the problem. Can you please provide a sample app that reproduces the problem?
Thanks

hilalkale
Posts: 16
Joined: 09 Mar 2022, 09:23

Re: problem with log4j2

Post by hilalkale »

Hi all,

During our investigations we found out that using log4j 2.17.3-snapshot version solves the problem for now. We have some appender implementations which use PatternLayout class from log4j. And during initialization some lookup classes are searched (SpringLookup, DockerLookup...etc.) via Interpolator by log4j and fails as we don't have a dependency to those. And whenever log4j fails OWS side also can not handle that and fails too. So anyone who have the same problem might try using snapshot version of log4j as a workaround. But as a final solution OWS side should also be able to handle this too imho.

Janak Mulani
Posts: 497
Joined: 24 Mar 2020, 13:37

Re: problem with log4j2

Post by Janak Mulani »

Thanks very much for sharing the solution. Would it be possible to provide a small snippet of your application which is using "some appender implementations which use PatternLayout class from log4"? We can then debug why OWS was not able to find classes with Log4J 2.17.1 and why it is working with 2.17.3-snapshot.Thanks.

hilalkale
Posts: 16
Joined: 09 Mar 2022, 09:23

Re: problem with log4j2

Post by hilalkale »

Hi Janak,

As soon as I have time, I will try to prepare a sample app and share with you. Thanks.

KlausFriese
Posts: 6
Joined: 19 Jul 2021, 10:33

Re: problem with log4j2

Post by KlausFriese »

log4j 2.18 is released and the problem is solved.
Thanks to hilalkale who found that this problem didn't appear in a 2.17.3 snapshot, finally we just waited for the 2.18 release :)

hilalkale
Posts: 16
Joined: 09 Mar 2022, 09:23

Re: problem with log4j2

Post by hilalkale »

Hey KlausFriese, glad I could help :) We also switched to 2.18 release as soon as it is published.

Post Reply