Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using Map.of in a ContextDataProvider implementation throws UOE #2098

Closed
slinkydeveloper opened this issue Dec 15, 2023 · 2 comments · Fixed by #2101
Closed

Using Map.of in a ContextDataProvider implementation throws UOE #2098

slinkydeveloper opened this issue Dec 15, 2023 · 2 comments · Fixed by #2101
Assignees
Labels
bug Incorrect, unexpected, or unintended behavior of existing code
Milestone

Comments

@slinkydeveloper
Copy link

Description

I'm using logj2 with a custom ContextDataProvider, and then using the aws lambda appender. 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)

@ppkarwasz ppkarwasz added the bug Incorrect, unexpected, or unintended behavior of existing code label Dec 15, 2023
@ppkarwasz ppkarwasz added this to the 2.22.1 milestone Dec 15, 2023
@ppkarwasz ppkarwasz self-assigned this Dec 15, 2023
@slinkydeveloper
Copy link
Author

FYI the aws lambda appender has probably nothing to do with this issue anyway, as i've found out here #2099

ppkarwasz added a commit to ppkarwasz/logging-log4j2 that referenced this issue Dec 15, 2023
This PR marks `StringMap`s generated from Java `Map`s as frozen if the
wrapped map is immutable.

Fixes apache#2098
ppkarwasz added a commit to ppkarwasz/logging-log4j2 that referenced this issue Dec 15, 2023
This PR marks `StringMap`s generated from Java `Map`s as frozen if the
wrapped map is immutable.

Fixes apache#2098
@ppkarwasz ppkarwasz linked a pull request Dec 15, 2023 that will close this issue
@ppkarwasz
Copy link
Contributor

@slinkydeveloper,

Thanks for reporting this issue. Our Java Map to StringMap didn't check if the wrapped map is immutable and didn't mark it as frozen.

This should be fixed in the next release.

ppkarwasz added a commit to ppkarwasz/logging-log4j2 that referenced this issue Dec 21, 2023
This PR marks `StringMap`s generated from Java `Map`s as frozen if the
wrapped map is immutable.

Fixes apache#2098
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Incorrect, unexpected, or unintended behavior of existing code
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants