You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@logging.apache.org by "vertex-github (via GitHub)" <gi...@apache.org> on 2023/08/02 19:37:41 UTC

[I] JSON Format with nanoseconds causes ArrayIndexOutOfBoundsException (logging-log4j2)

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

   ## Description
   
   Configure JSONTemplate with a custom timestamp formatter:
   
   <?xml version="1.0" encoding="UTF-8"?>
   
   <Configuration status="WARN" strict="true" packages="org.apache.logging.log4j.layout.template.json" shutdownHook="disable">
       <Appenders>
           <Console name="STDOUT">
               <JsonTemplateLayout eventTemplateUri="classpath:JsonTemplate.json" recyclerFactory="queue" locationInfoEnabled="true" />
           </Console>
       </Appenders>
   
       <Loggers>
           <Root level="INFO" includeLocation="true">
               <AppenderRef ref="STDOUT"/>
           </Root>
       </Loggers>
   </Configuration>
   
   JsonTemplate.json:
   
     "timestamp": {
       "$resolver": "timestamp",
       "pattern": {
         "format": "yyyy-MM-dd HH:mm:ss,nnnnnnnnn"
       }
     },
   
   (This is one of the formats specified in `FixedDateFormat.FixedFormat.DEFAULT_NANOS`
   
   ## Configuration
   
   **Version:** 2.19.0
   
   **Operating system:** Windows 10
   
   **JDK:** Amazon Coretto JDK17.0.3
   
   ```
   [Stacktraces, errors, etc. relevant applications logs.]
   2023-08-02 15:28:04,391 main WARN skipping the failed formatter factory "org.apache.logging.log4j.layout.template.json.util.InstantFormatter$Log4jFixedFormatterFactory@4d02f94e" java.lang.ArrayIndexOutOfBoundsException: Index 23 out of bounds for length 23
   	at org.apache.logging.log4j.core.util.datetime.FixedDateFormat.formatNanoOfMillisecond(FixedDateFormat.java:703)
   	at org.apache.logging.log4j.core.util.datetime.FixedDateFormat.formatInstant(FixedDateFormat.java:592)
   	at org.apache.logging.log4j.layout.template.json.util.InstantFormatter$Log4jFixedFormatter.format(InstantFormatter.java:338)
   	at org.apache.logging.log4j.layout.template.json.util.InstantFormatter.patternSupported(InstantFormatter.java:376)
   	at org.apache.logging.log4j.layout.template.json.util.InstantFormatter.access$700(InstantFormatter.java:42)
   	at org.apache.logging.log4j.layout.template.json.util.InstantFormatter$Log4jFixedFormatterFactory.createIfSupported(InstantFormatter.java:312)
   	at org.apache.logging.log4j.layout.template.json.util.InstantFormatter.lambda$new$0(InstantFormatter.java:62)
   	at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197)
   	at java.base/java.util.Spliterators$ArraySpliterator.tryAdvance(Spliterators.java:1002)
   	at java.base/java.util.stream.ReferencePipeline.forEachWithCancel(ReferencePipeline.java:129)
   	at java.base/java.util.stream.AbstractPipeline.copyIntoWithCancel(AbstractPipeline.java:527)
   	at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:513)
   	at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
   	at java.base/java.util.stream.FindOps$FindOp.evaluateSequential(FindOps.java:150)
   	at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
   	at java.base/java.util.stream.ReferencePipeline.findFirst(ReferencePipeline.java:647)
   	at org.apache.logging.log4j.layout.template.json.util.InstantFormatter.<init>(InstantFormatter.java:72)
   	at org.apache.logging.log4j.layout.template.json.util.InstantFormatter.<init>(InstantFormatter.java:42)
   	at org.apache.logging.log4j.layout.template.json.util.InstantFormatter$Builder.build(InstantFormatter.java:149)
   	at org.apache.logging.log4j.layout.template.json.resolver.TimestampResolver$PatternResolverContext.<init>(TimestampResolver.java:232)
   	at org.apache.logging.log4j.layout.template.json.resolver.TimestampResolver$PatternResolverContext.fromConfig(TimestampResolver.java:241)
   	at org.apache.logging.log4j.layout.template.json.resolver.TimestampResolver$PatternResolverContext.access$300(TimestampResolver.java:215)
   	at org.apache.logging.log4j.layout.template.json.resolver.TimestampResolver.createPatternResolver(TimestampResolver.java:325)
   	at org.apache.logging.log4j.layout.template.json.resolver.TimestampResolver.createResolver(TimestampResolver.java:212)
   	at org.apache.logging.log4j.layout.template.json.resolver.TimestampResolver.<init>(TimestampResolver.java:199)
   	at org.apache.logging.log4j.layout.template.json.resolver.TimestampResolverFactory.create(TimestampResolverFactory.java:46)
   	at org.apache.logging.log4j.layout.template.json.resolver.TimestampResolverFactory.create(TimestampResolverFactory.java:25)
   	at org.apache.logging.log4j.layout.template.json.resolver.TemplateResolvers.ofResolver(TemplateResolvers.java:442)
   	at org.apache.logging.log4j.layout.template.json.resolver.TemplateResolvers.ofMap(TemplateResolvers.java:221)
   	at org.apache.logging.log4j.layout.template.json.resolver.TemplateResolvers.ofObject(TemplateResolvers.java:141)
   	at org.apache.logging.log4j.layout.template.json.resolver.TemplateResolvers.lambda$populateFieldResolverMethods$1(TemplateResolvers.java:250)
   	at java.base/java.util.LinkedHashMap.forEach(LinkedHashMap.java:721)
   	at org.apache.logging.log4j.layout.template.json.resolver.TemplateResolvers.populateFieldResolverMethods(TemplateResolvers.java:249)
   	at org.apache.logging.log4j.layout.template.json.resolver.TemplateResolvers.ofMap(TemplateResolvers.java:226)
   	at org.apache.logging.log4j.layout.template.json.resolver.TemplateResolvers.ofObject(TemplateResolvers.java:141)
   	at org.apache.logging.log4j.layout.template.json.resolver.TemplateResolvers.ofTemplate(TemplateResolvers.java:123)
   	at org.apache.logging.log4j.layout.template.json.JsonTemplateLayout.createEventResolver(JsonTemplateLayout.java:168)
   	at org.apache.logging.log4j.layout.template.json.JsonTemplateLayout.<init>(JsonTemplateLayout.java:109)
   	at org.apache.logging.log4j.layout.template.json.JsonTemplateLayout.<init>(JsonTemplateLayout.java:63)
   	at org.apache.logging.log4j.layout.template.json.JsonTemplateLayout$Builder.build(JsonTemplateLayout.java:551)
   	at org.apache.logging.log4j.layout.template.json.JsonTemplateLayout$Builder.build(JsonTemplateLayout.java:347)
   	at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.build(PluginBuilder.java:124)
   	at org.apache.logging.log4j.core.config.AbstractConfiguration.createPluginObject(AbstractConfiguration.java:1138)
   	at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:1063)
   	at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:1055)
   	at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:1055)
   	at org.apache.logging.log4j.core.config.AbstractConfiguration.doConfigure(AbstractConfiguration.java:664)
   	at org.apache.logging.log4j.core.config.AbstractConfiguration.initialize(AbstractConfiguration.java:258)
   	at org.apache.logging.log4j.core.config.AbstractConfiguration.start(AbstractConfiguration.java:304)
   	at org.apache.logging.log4j.core.LoggerContext.setConfiguration(LoggerContext.java:621)
   	at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:694)
   	at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:711)
   	at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:253)
   	at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:155)
   	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:61)
   	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:391)
   	at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:416)
   	at org.example.Main.<clinit>(Main.java:8)
   
   ```
   
   ## Reproduction
   
   Configure simple maven project with the above import, and log4j2.xml config. Log a line.
   
   The `pattern.length` seems to be returning 23 - but this doesn't seem to be taking into account the 6 additional chars for micros and nanos.
   


-- 
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] JSON Format with nanoseconds causes ArrayIndexOutOfBoundsException (logging-log4j2)

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

   @vertex-github, thanks so much for the report. It feels like a locale-related problem. #1419 should be fixing this issue. Would you mind checking if `2.20.1-SNAPSHOT` solves the issue for you, please?
   
   Could you also share the locale used, please?


-- 
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] JSON Format with nanoseconds causes ArrayIndexOutOfBoundsException (logging-log4j2)

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

   @vertex-github, thanks so much for the prompt feedback, much appreciated! Glad that the issue is resolved.


-- 
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] JSON Format with nanoseconds causes ArrayIndexOutOfBoundsException (logging-log4j2)

Posted by "vy (via GitHub)" <gi...@apache.org>.
vy closed issue #1658: JSON Format with nanoseconds causes ArrayIndexOutOfBoundsException
URL: https://github.com/apache/logging-log4j2/issues/1658


-- 
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] JSON Format with nanoseconds causes ArrayIndexOutOfBoundsException (logging-log4j2)

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

   US English,  I took a look at the PR. That fixes the buffer overruns due to
   timezones specification in the pattern. I'm not sure if it catches the
   nanos as well but will try and pull and snapshot build this morning to check
   
   N
   
   On Thu, Aug 3, 2023, 07:13 'Volkan Yazıcı' via github <
   ***@***.***> wrote:
   
   > @vertex-github <https://github.com/vertex-github>, thanks so much for the
   > report. It feels like a locale-related problem. #1419
   > <https://github.com/apache/logging-log4j2/pull/1419> should be fixing
   > this issue. Would you mind checking if 2.20.1-SNAPSHOT solves the issue
   > for you, please?
   >
   > Could you also share the locale used, please?
   >
   > —
   > Reply to this email directly, view it on GitHub
   > <https://github.com/apache/logging-log4j2/issues/1658#issuecomment-1663794500>,
   > or unsubscribe
   > <https://github.com/notifications/unsubscribe-auth/ABRJVJJGLF5APH4RFTJ6HMLXTOBU3ANCNFSM6AAAAAA3BXVOUQ>
   > .
   > You are receiving this because you were mentioned.Message ID:
   > ***@***.***>
   >
   


-- 
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] JSON Format with nanoseconds causes ArrayIndexOutOfBoundsException (logging-log4j2)

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

   Snapshot fixed the issue. I did not try with nanos + timezone though.
   
   Thanks
   
   
   On Thu, Aug 3, 2023, 07:24 Pratt, Nick ***@***.***> wrote:
   
   > US English,  I took a look at the PR. That fixes the buffer overruns due
   > to timezones specification in the pattern. I'm not sure if it catches the
   > nanos as well but will try and pull and snapshot build this morning to check
   >
   > N
   >
   > On Thu, Aug 3, 2023, 07:13 'Volkan Yazıcı' via github <
   > ***@***.***> wrote:
   >
   >> @vertex-github <https://github.com/vertex-github>, thanks so much for
   >> the report. It feels like a locale-related problem. #1419
   >> <https://github.com/apache/logging-log4j2/pull/1419> should be fixing
   >> this issue. Would you mind checking if 2.20.1-SNAPSHOT solves the issue
   >> for you, please?
   >>
   >> Could you also share the locale used, please?
   >>
   >> —
   >> Reply to this email directly, view it on GitHub
   >> <https://github.com/apache/logging-log4j2/issues/1658#issuecomment-1663794500>,
   >> or unsubscribe
   >> <https://github.com/notifications/unsubscribe-auth/ABRJVJJGLF5APH4RFTJ6HMLXTOBU3ANCNFSM6AAAAAA3BXVOUQ>
   >> .
   >> You are receiving this because you were mentioned.Message ID:
   >> ***@***.***>
   >>
   >
   


-- 
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