-
Notifications
You must be signed in to change notification settings - Fork 5
Log4j2 throws UnsupportedOperationException #97
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
Comments
Fixes reactiverse#97 VertxContextDataProvider relied on the default implementation of ContextDataProvider.supplyStringMap which expects supplyContextData to return a mutable map. But VertxContextDataProvider returns an immutable map and this is why sometimes (depending on log4j2 config) an UOE can be thrown. In this commit, VertxContextDataProvider now returns a custom implementation of StringMap. This implementation is "frozen", which means log4j2 will not attempt to modify it. Because log4j2 expects the StringMap entries to be processed in order, the ContextualDataImpl.getAll implementation has been modified to return a map sorted on its keys. The map is not typed with SortedMap to reduce the number of methods to implement.
@BenjaminTanguay I've sent PR #98 which should solve the issue. Can you give it a try? |
@BenjaminTanguay I'm asking because I wasn't able to reproduce locally |
I'll check... |
@tsegismont The fix seems to work. Thank you for the help! |
same problem, thank u guys |
I am concerned that I wasn't able to reproduce. I can see how the previous implementation did not conform to log4j2 expectations, but I would prefer to have a test to add to this PR. Is any of you able to provide a simple reproducer ? |
I am not familiar with your library and environment so building a test for it may be stretching it. I'll try to create a small sample project to reproduce the problem and you can derive a test from that. |
I tried all day creating a small reproducer based on our production code and I still can't do it. I tried a bunch of permutations but I can't isolate the factor responsible for triggering the bug. I can't justify working on this for much longer so I'll just stop. I may or may not come back to this on my own time. |
Thanks for trying @BenjaminTanguay . I'll go ahead and merge this. |
Fixes reactiverse#97 VertxContextDataProvider relied on the default implementation of ContextDataProvider.supplyStringMap which expects supplyContextData to return a mutable map. But VertxContextDataProvider returns an immutable map and this is why sometimes (depending on log4j2 config) an UOE can be thrown. In this commit, VertxContextDataProvider now returns a custom implementation of StringMap. This implementation is "frozen", which means log4j2 will not attempt to modify it. Because log4j2 expects the StringMap entries to be processed in order, the ContextualDataImpl.getAll implementation has been modified to return a map sorted on its keys. The map is not typed with SortedMap to reduce the number of methods to implement.
* UOE may be thrown when using log4j2 with context data provider Fixes #97 VertxContextDataProvider relied on the default implementation of ContextDataProvider.supplyStringMap which expects supplyContextData to return a mutable map. But VertxContextDataProvider returns an immutable map and this is why sometimes (depending on log4j2 config) an UOE can be thrown. In this commit, VertxContextDataProvider now returns a custom implementation of StringMap. This implementation is "frozen", which means log4j2 will not attempt to modify it. Because log4j2 expects the StringMap entries to be processed in order, the ContextualDataImpl.getAll implementation has been modified to return a map sorted on its keys. The map is not typed with SortedMap to reduce the number of methods to implement. * Simplify implementation Safer since we can't reproduce the original bug
Fixed in version |
Background info:
Vertx 4.5.1
slf4j 2.0.9
log4j 2.21.0
reactiverse-contextual-logging 1.1.2
Problem:
When logging to the console, the following stacktrace is produced:
After analysis, I've found that the problem seems to be related to this library. More specifically, the class
io.reactiverse.contextual.logging.VertxContextDataProvider
creates an immutable map that the logging framework later attempts to clear, causing the problem. This stacktrace is repeated for every line that is subsequently logged to the console. I tried creating my own instance of the VertxContextDataProvider with a regular HashMap instead of an immutable collection and the problem seems to be resolved. My problem is that I don't know whether I'm introducing side-effects by changing the data structure accessibility.Here is the log4j xml file configuration used to produce the problem:
The text was updated successfully, but these errors were encountered: