You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@logging.apache.org by "slinkydeveloper (via GitHub)" <gi...@apache.org> on 2023/12/15 11:50:23 UTC

[I] Using `Map.of` in a `ContextDataProvider` implementation throws UOE (logging-log4j2)

slinkydeveloper opened a new issue, #2098:
URL: https://github.com/apache/logging-log4j2/issues/2098

   ## Description
   
   I'm using logj2 with a custom `ContextDataProvider`, and then using the [aws lambda appender](https://docs.aws.amazon.com/lambda/latest/dg/java-logging.html#java-logging-log4j2). My `ContextDataProvider` implementation uses `Map.of` methods from JDK to create cheap immutable maps, but apparently that doesn't work and throws UOE.
   
   In the stacktrace it's shown that a method down the stack invokes `ImmutableCollections.AbstractImmutableMap::clear`, which throws UOE. Interesting enough, in many online examples they use `Collections.emptyMap()` for the empty map, which doesn't throw UOE on `clear`.
   
   What puzzles me though is that I wasn't able to reproduce this issue with the log4j2-core console appender. Is the amazon appender doing something strange, or is this a bug of log4j2-core?
   
   ## Configuration
   
   **Version:** 2.22.0
   
   **Operating system:** Linux
   
   **JDK:** 21 (amazon)
   
   ## Logs
   
   ```
   2023-12-15T11:26:15.337000+00:00  WARN StatusConsoleListener org.apache.logging.log4j.spi.AbstractLogger caught java.lang.UnsupportedOperationException logging ReusableSimpleMessage: Incremented counter!
   2023-12-15T11:26:15.338000+00:00  java.lang.UnsupportedOperationException
   2023-12-15T11:26:15.338000+00:00  at java.base/java.util.ImmutableCollections.uoe(Unknown Source)
   2023-12-15T11:26:15.338000+00:00  at java.base/java.util.ImmutableCollections$AbstractImmutableMap.clear(Unknown Source)
   2023-12-15T11:26:15.338000+00:00  at org.apache.logging.log4j.core.impl.JdkMapAdapterStringMap.clear(JdkMapAdapterStringMap.java:122)
   2023-12-15T11:26:15.338000+00:00  at org.apache.logging.log4j.core.impl.MutableLogEvent.clear(MutableLogEvent.java:143)
   2023-12-15T11:26:15.338000+00:00  at org.apache.logging.log4j.core.impl.ReusableLogEventFactory.release(ReusableLogEventFactory.java:141)
   2023-12-15T11:26:15.338000+00:00  at org.apache.logging.log4j.core.config.LoggerConfig.log(LoggerConfig.java:578)
   2023-12-15T11:26:15.338000+00:00  at org.apache.logging.log4j.core.config.AwaitCompletionReliabilityStrategy.log(AwaitCompletionReliabilityStrategy.java:92)
   2023-12-15T11:26:15.338000+00:00  at org.apache.logging.log4j.core.Logger.log(Logger.java:169)
   2023-12-15T11:26:15.338000+00:00  at org.apache.logging.log4j.spi.AbstractLogger.tryLogMessage(AbstractLogger.java:2933)
   2023-12-15T11:26:15.338000+00:00  at org.apache.logging.log4j.spi.AbstractLogger.logMessageTrackRecursion(AbstractLogger.java:2886)
   2023-12-15T11:26:15.338000+00:00  at org.apache.logging.log4j.spi.AbstractLogger.logMessageSafely(AbstractLogger.java:2868)
   2023-12-15T11:26:15.338000+00:00  at org.apache.logging.log4j.spi.AbstractLogger.logMessage(AbstractLogger.java:2647)
   2023-12-15T11:26:15.338000+00:00  at org.apache.logging.log4j.spi.AbstractLogger.logIfEnabled(AbstractLogger.java:2594)
   2023-12-15T11:26:15.339000+00:00  at org.apache.logging.log4j.spi.AbstractLogger.info(AbstractLogger.java:1597)
   2023-12-15T11:26:15.339000+00:00  at dev.restate.sdk.examples.Greeter.greet(Greeter.kt:31)
   [... My application stacktrace ...]
   2023-12-15T11:26:15.340000+00:00  at dev.restate.sdk.lambda.BaseRestateLambdaHandler.handleRequest(BaseRestateLambdaHandler.java:28)
   2023-12-15T11:26:15.340000+00:00  at com.amazonaws.services.lambda.runtime.api.client.EventHandlerLoader$PojoHandlerAsStreamHandler.handleRequest(EventHandlerLoader.java:202)
   2023-12-15T11:26:15.340000+00:00  at com.amazonaws.services.lambda.runtime.api.client.EventHandlerLoader$2.call(EventHandlerLoader.java:905)
   2023-12-15T11:26:15.340000+00:00  at com.amazonaws.services.lambda.runtime.api.client.AWSLambda.startRuntime(AWSLambda.java:245)
   2023-12-15T11:26:15.340000+00:00  at com.amazonaws.services.lambda.runtime.api.client.AWSLambda.startRuntime(AWSLambda.java:197)
   2023-12-15T11:26:15.340000+00:00  at com.amazonaws.services.lambda.runtime.api.client.AWSLambda.main(AWSLambda.java:187)
   
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@logging.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Using `Map.of` in a `ContextDataProvider` implementation throws UOE (logging-log4j2)

Posted by "ppkarwasz (via GitHub)" <gi...@apache.org>.
ppkarwasz closed issue #2098: Using `Map.of` in a `ContextDataProvider` implementation throws UOE 
URL: https://github.com/apache/logging-log4j2/issues/2098


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@logging.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Using `Map.of` in a `ContextDataProvider` implementation throws UOE (logging-log4j2)

Posted by "ppkarwasz (via GitHub)" <gi...@apache.org>.
ppkarwasz commented on issue #2098:
URL: https://github.com/apache/logging-log4j2/issues/2098#issuecomment-1858580112

   @slinkydeveloper,
   
   Thanks for reporting this issue. Our Java `Map` to [`StringMap`](https://logging.apache.org/log4j/2.x/javadoc/log4j-api/org/apache/logging/log4j/util/StringMap.html) didn't check if the wrapped map is immutable and didn't mark it as `frozen`.
   
   This should be fixed in the next release.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@logging.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Using `Map.of` in a `ContextDataProvider` implementation throws UOE (logging-log4j2)

Posted by "slinkydeveloper (via GitHub)" <gi...@apache.org>.
slinkydeveloper commented on issue #2098:
URL: https://github.com/apache/logging-log4j2/issues/2098#issuecomment-1857969826

   FYI the aws lambda appender has probably nothing to do with this issue anyway, as i've found out here https://github.com/apache/logging-log4j2/issues/2099


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@logging.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org