You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@logging.apache.org by "Ralph Goers (JIRA)" <ji...@apache.org> on 2017/11/26 23:27:00 UTC

[jira] [Comment Edited] (LOG4J2-2129) Log4j2 throws NoClassDefFoundError in Java 9

    [ https://issues.apache.org/jira/browse/LOG4J2-2129?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16266241#comment-16266241 ] 

Ralph Goers edited comment on LOG4J2-2129 at 11/26/17 11:26 PM:
----------------------------------------------------------------

I see that we are calling ServiceLoader to load a PropertySource from PropertiesUtil. I don't see why a uses for PropertiesUtil is necessary. However, I do see another ServiceLoader call to load a ThreadInfoFactory class in ThreadDumpMessage, so that needs to be added as well.


was (Author: ralph.goers@dslextreme.com):
Have you found any documentation on why the two "uses" declarations are necessary? All I could find is that uses is required to name the class used by the ServiceLoader. Not that there is anything wrong with your fix but I am wondering why it is needed.

> Log4j2 throws NoClassDefFoundError in Java 9
> --------------------------------------------
>
>                 Key: LOG4J2-2129
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-2129
>             Project: Log4j 2
>          Issue Type: Bug
>          Components: API
>    Affects Versions: 2.10.0, 2.10.1
>         Environment: Java 9
>            Reporter: Blazej
>
> When I execute a sample project (https://github.com/bbucko/log4j2-jpms-sample) in Java 9 a following exception is thrown:
> {code}
> Exception in thread "main" java.lang.NoClassDefFoundError: Could not initialize class org.apache.logging.log4j.util.PropertiesUtil
> 	at org.apache.logging.log4j/org.apache.logging.log4j.status.StatusLogger.<clinit>(StatusLogger.java:71)
> 	at org.apache.logging.log4j/org.apache.logging.log4j.LogManager.<clinit>(LogManager.java:60)
> {code}
> Exception is a little bit misleading because it seems that true root cause can be found here:
> {code}
> java.util.ServiceConfigurationError: org.apache.logging.log4j.util.PropertySource: module org.apache.logging.log4j does not declare `uses`
> 	at java.base/java.util.ServiceLoader.fail(ServiceLoader.java:588)
> 	at java.base/java.util.ServiceLoader.checkCaller(ServiceLoader.java:574)
> 	at java.base/java.util.ServiceLoader.<init>(ServiceLoader.java:503)
> 	at java.base/java.util.ServiceLoader.load(ServiceLoader.java:1684)
> 	at org.apache.logging.log4j/org.apache.logging.log4j.util.PropertiesUtil$Environment.<init>(PropertiesUtil.java:319)
> 	at org.apache.logging.log4j/org.apache.logging.log4j.util.PropertiesUtil$Environment.<init>(PropertiesUtil.java:310)
> 	at org.apache.logging.log4j/org.apache.logging.log4j.util.PropertiesUtil.<init>(PropertiesUtil.java:69)
> 	at org.apache.logging.log4j/org.apache.logging.log4j.util.PropertiesUtil.<clinit>(PropertiesUtil.java:49)
> 	at org.apache.logging.log4j/org.apache.logging.log4j.util.Constants.<clinit>(Constants.java:30)
> 	at java.base/java.lang.Class.forName0(Native Method)
> 	at java.base/java.lang.Class.forName(Class.java:375)
> 	at org.apache.logging.log4j/org.apache.logging.log4j.spi.AbstractLogger.createClassForProperty(AbstractLogger.java:198)
> 	at org.apache.logging.log4j/org.apache.logging.log4j.spi.AbstractLogger.<clinit>(AbstractLogger.java:88)
> 	at org.apache.logging.log4j/org.apache.logging.log4j.LogManager.<clinit>(LogManager.java:60)
> {code}



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)