AbstractConfiguration#initialize - making two passes generates invalid configuration - no check if initialization has already been performed

Aperta
#3,449 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
java
Ambito
backend

Direzione di ricerca

Inizia con AbstractConfiguration#initialize e Configuration#doConfigure, quindi esamina il caso Configurator1Test esistente menzionato nel report. Riproduci la sequenza builder.build() seguita da config.initialize() e verifica che una seconda inizializzazione non elimini gli appender CONSOLE e RollingFile configurati né altre configurazioni annidate.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Log4j 2.24.3

Repeated calls to the Configuration#doConfigure method discard appenders (and maybe other inforrmation).

In my example, I have a configuration with two defined appenders ("CONSOLE" and "RollingFile").

Taken from another test case, lets assume I use a BuiltConfiguration with a ConfigurationBuilder and create the and initialized configuration and then initialize it again (the first initialization happens in the build method if I don't call builder.build(false). (Admittedly, this is redundant and strictly incorrect; however, it is possible and I found an instance of this in the Configurator1Test unit-test.)

final Configuration config = builder.build();
config.initialize();

In the first pass, the rootNode tree is processed and through a call to PluginElementVisitor#visit(....) all nested nodes are removed and the top level child node is assigned an built object.

Image

If a second pass is made, the config.initialize() method performs no check to see if it has already been initialized (State.INITIALIZED or later). This results in another runthrough of doConfigure() and now the child nodes are missing because they have been visited and removed,

Here before the 2nd-pass of createConfigurationon the "Appenders" node:

Image

Now however, due to the missing child information, the object list of configured appenders is empty and the two previously defined appenders are gone.

Image

So the second configure cleared the previous run's appenders (and possibly other nested configuration).

I think the easy solution would be to test the state in the initialize method and if not INITIALIZING just log and return; however, I don't know if that would have other side-efffects.

Lingua principale
Java
Stelle
3.6k
Fork
1.8k
Merge medio
5g 6h
PR unite (30g)
24

Preparare l'ambiente

  • Nessun Dockerfile né file Docker Compose
  • Ha un modello di pull request
  • Nessuna guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di apache/logging-log4j2

Tutte le issue di apache/logging-log4j2

Issue simili

Altre issue su Java

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.