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

Phong X. Nguyen commented on LOG4J2-3231:
-----------------------------------------

Sure. Stack trace below: 

(After looking more carefully, it looks like someone's unit test stubs out 
{{InetAddress}, which is probably triggering the problem. Still, should this be 
fixed?)
 
{code:java}
java.lang.ExceptionInInitializerError
        at java.net.NetworkInterface.<clinit>(NetworkInterface.java:65)
        at 
org.apache.logging.log4j.core.util.NetUtils.getLocalIps(NetUtils.java:102)
        at 
org.apache.logging.log4j.core.net.JndiManager.<clinit>(JndiManager.java:61)
        at 
org.apache.logging.log4j.core.lookup.Interpolator.<init>(Interpolator.java:112)
        at 
org.apache.logging.log4j.core.config.AbstractConfiguration.<init>(AbstractConfiguration.java:131)
        at 
org.apache.logging.log4j.core.config.NullConfiguration.<init>(NullConfiguration.java:32)
        at 
org.apache.logging.log4j.core.LoggerContext.<clinit>(LoggerContext.java:85)
        at 
org.apache.logging.log4j.core.selector.ClassLoaderContextSelector.createContext(ClassLoaderContextSelector.java:254)
        at 
org.apache.logging.log4j.core.selector.ClassLoaderContextSelector.locateContext(ClassLoaderContextSelector.java:218)
        at 
org.apache.logging.log4j.core.selector.ClassLoaderContextSelector.getContext(ClassLoaderContextSelector.java:136)
        at 
org.apache.logging.log4j.core.selector.ClassLoaderContextSelector.getContext(ClassLoaderContextSelector.java:123)
        at 
org.apache.logging.log4j.core.selector.ClassLoaderContextSelector.getContext(ClassLoaderContextSelector.java:117)
        at 
org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:150)
        at 
org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:47)
        at org.apache.logging.log4j.LogManager.getContext(LogManager.java:196)
        at 
org.apache.logging.log4j.spi.AbstractLoggerAdapter.getContext(AbstractLoggerAdapter.java:137)
        at 
org.apache.logging.slf4j.Log4jLoggerFactory.getContext(Log4jLoggerFactory.java:55)
        at 
org.apache.logging.log4j.spi.AbstractLoggerAdapter.getLogger(AbstractLoggerAdapter.java:47)
        at 
org.apache.logging.slf4j.Log4jLoggerFactory.getLogger(Log4jLoggerFactory.java:33)
        at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:363)
        at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:388)
        at org.example.App.<clinit>(App.java:12)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
        at 
org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:365)
        at 
org.apache.maven.surefire.junit4.JUnit4Provider.executeWithRerun(JUnit4Provider.java:273)
        at 
org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:238)
        at 
org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:159)
        at 
org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:384)
        at 
org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:345)
        at 
org.apache.maven.surefire.booter.ForkedBooter.execute(ForkedBooter.java:126)
        at 
org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:418)
Caused by: java.lang.NullPointerException
        at java.net.Inet6Address.<init>(Inet6Address.java:377)
        at java.net.NetworkInterface.getAll(Native Method)
        at 
java.net.NetworkInterface.getNetworkInterfaces(NetworkInterface.java:355)
        at 
java.net.DefaultInterface.chooseDefaultInterface(DefaultInterface.java:67)
        at java.net.DefaultInterface.<clinit>(DefaultInterface.java:46)
        ... 32 more
{code}
{code:java}
package org.example;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Hello world!
 *
 */
public class App 
{
    private static final Logger logger = LoggerFactory.getLogger(App.class);

    public int foo() {
        logger.info("Test Foo!");
        return 10;
    }

    public int bar() {
        logger.info("Test Bar!");
        return foo();
    }

    public static void main( String[] args )
    {
        System.out.println( "Hello World!" );
    }
}
{code}
{code:java}
package org.example;

import static org.junit.Assert.assertEquals;

import mockit.Expectations;
import mockit.Mocked;
import mockit.Tested;
import mockit.integration.junit4.JMockit;
import org.junit.Test;
import org.junit.runner.RunWith;

import java.net.InetAddress;

/**
 * Unit test for simple App.
 */
@RunWith(JMockit.class)
public class AppTest 
{
    @Tested
    App app;

    @Mocked(stubOutClassInitialization = true)
    InetAddress inetAddress;

    @Test
    public void testFoo()
    {
        new Expectations(app) {{
            app.foo();
            result = 15;
        }};
        assertEquals(15, app.bar());
    }
}
{code}
{code:xml}
<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/xsd/maven-4.0.0.xsd";>
  <modelVersion>4.0.0</modelVersion>

  <groupId>org.example</groupId>
  <artifactId>log4j2-issue</artifactId>
  <version>1.0-SNAPSHOT</version>

  <name>log4j2-issue</name>
  <!-- FIXME change it to the project's website -->
  <url>http://www.example.com</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
  </properties>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.13.2</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-api</artifactId>
      <version>1.7.32</version>
    </dependency>
    <dependency>
      <groupId>org.apache.logging.log4j</groupId>
      <artifactId>log4j-slf4j-impl</artifactId>
      <version>2.16.0</version>
    </dependency>
    <dependency>
      <groupId>org.apache.logging.log4j</groupId>
      <artifactId>log4j-api</artifactId>
      <version>2.16.0</version>
    </dependency>
    <dependency>
      <groupId>org.apache.logging.log4j</groupId>
      <artifactId>log4j-core</artifactId>
      <version>2.16.0</version>
    </dependency>
    <dependency>
      <groupId>org.apache.logging.log4j</groupId>
      <artifactId>log4j-1.2-api</artifactId>
      <version>2.16.0</version>
    </dependency>
    <dependency>
      <groupId>org.jmockit</groupId>
      <artifactId>jmockit</artifactId>
      <version>1.24</version>
      <scope>test</scope>
    </dependency>
  </dependencies>

  <build>
    <pluginManagement><!-- lock down plugins versions to avoid using Maven 
defaults (may be moved to parent pom) -->
      <plugins>
        <!-- clean lifecycle, see 
https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle 
-->
        <plugin>
          <artifactId>maven-clean-plugin</artifactId>
          <version>3.1.0</version>
        </plugin>
        <!-- default lifecycle, jar packaging: see 
https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging
 -->
        <plugin>
          <artifactId>maven-resources-plugin</artifactId>
          <version>3.0.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-compiler-plugin</artifactId>
          <version>3.8.0</version>
        </plugin>
        <plugin>
          <artifactId>maven-surefire-plugin</artifactId>
          <version>2.22.1</version>
        </plugin>
        <plugin>
          <artifactId>maven-jar-plugin</artifactId>
          <version>3.0.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-install-plugin</artifactId>
          <version>2.5.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-deploy-plugin</artifactId>
          <version>2.8.2</version>
        </plugin>
        <!-- site lifecycle, see 
https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle 
-->
        <plugin>
          <artifactId>maven-site-plugin</artifactId>
          <version>3.7.1</version>
        </plugin>
        <plugin>
          <artifactId>maven-project-info-reports-plugin</artifactId>
          <version>3.0.0</version>
        </plugin>
      </plugins>
    </pluginManagement>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <configuration>
          <trimStackTrace>false</trimStackTrace>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>
{code}

> JndiManager.isJndiEnabled generates a call to NetUtils.getLocalIps
> ------------------------------------------------------------------
>
>                 Key: LOG4J2-3231
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-3231
>             Project: Log4j 2
>          Issue Type: Bug
>          Components: Core
>    Affects Versions: 2.16.0
>            Reporter: Phong X. Nguyen
>            Priority: Major
>
> While trying to upgrade from 2.15.0 to 2.16.0, we discovered some of our unit 
> tests were failing. On further investigation, we realized that the new 
> {{JndiManager.isJndiEnabled()}} method, on first call, causes initialization 
> of all static members of {{{}JndiManager{}}}, including a call to 
> {{{}NetUtils.getLocalIps{}}}. In at least one of our unit test frameworks, 
> this generates a NullPointerException. 
> Could some of the {{permanentAllowed}} lists initialization be deferred to 
> avoid this issue? 



--
This message was sent by Atlassian Jira
(v8.20.1#820001)

Reply via email to