Log4j 2
  1. Log4j 2
  2. LOG4J2-719

Android throws NetworkOnMainThreadException during Log4j2 initialization

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.0
    • Fix Version/s: 2.0.1
    • Component/s: Configurators, Core
    • Labels:
      None
    • Environment:

      Android

      Description

      (Note that it is possible to work around this issue by modifying the policy and added internet permission to the Android manifest xml file.)

      Stacktrace:

      07-15 14:38:37.627    1243-1243/com.torointl.log4j2xtest W/dalvikvm﹕ Exception Landroid/os/NetworkOnMainThreadException; thrown while initializing Lcom/torointl/log4j2xtest/MyActivity;
      07-15 14:38:37.627    1243-1243/com.torointl.log4j2xtest W/dalvikvm﹕ Class init failed in newInstance call (Lcom/torointl/log4j2xtest/MyActivity;)
      07-15 14:38:37.627    1243-1243/com.torointl.log4j2xtest W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0xa4d72b20)
      07-15 14:38:37.639    1243-1243/com.torointl.log4j2xtest E/AndroidRuntime﹕ FATAL EXCEPTION: main
          Process: com.torointl.log4j2xtest, PID: 1243
          java.lang.ExceptionInInitializerError
                  at java.lang.Class.newInstanceImpl(Native Method)
                  at java.lang.Class.newInstance(Class.java:1208)
                  at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
                  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2112)
                  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
                  at android.app.ActivityThread.access$800(ActivityThread.java:135)
                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
                  at android.os.Handler.dispatchMessage(Handler.java:102)
                  at android.os.Looper.loop(Looper.java:136)
                  at android.app.ActivityThread.main(ActivityThread.java:5017)
                  at java.lang.reflect.Method.invokeNative(Native Method)
                  at java.lang.reflect.Method.invoke(Method.java:515)
                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
                  at dalvik.system.NativeStart.main(Native Method)
           Caused by: android.os.NetworkOnMainThreadException
                  at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1145)
                  at java.net.InetAddress.lookupHostByName(InetAddress.java:385)
                  at java.net.InetAddress.getLocalHost(InetAddress.java:365)
                  at org.apache.logging.log4j.core.util.NetUtils.getLocalHostname(NetUtils.java:47)
                  at org.apache.logging.log4j.core.LoggerContext.setConfiguration(LoggerContext.java:356)
                  at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:416)
                  at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:146)
                  at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:75)
                  at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:37)
                  at org.apache.logging.log4j.LogManager.getLogger(LogManager.java:473)
                  at com.torointl.log4j2xtest.MyActivity.<clinit>(MyActivity.java:14)
                  at java.lang.Class.newInstanceImpl(Native Method)
                  at java.lang.Class.newInstance(Class.java:1208)
                  at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
                  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2112)
                  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
                  at android.app.ActivityThread.access$800(ActivityThread.java:135)
                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
                  at android.os.Handler.dispatchMessage(Handler.java:102)
                  at android.os.Looper.loop(Looper.java:136)
                  at android.app.ActivityThread.main(ActivityThread.java:5017)
                  at java.lang.reflect.Method.invokeNative(Native Method)
                  at java.lang.reflect.Method.invoke(Method.java:515)
                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
                  at dalvik.system.NativeStart.main(Native Method)
      

        Issue Links

          Activity

            People

            • Assignee:
              Remko Popma
              Reporter:
              Remko Popma
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development