Fix logging with panache in entities #22734
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In case an entity class uses
io.quarkus.logging.Log
, it requirestwo bytecode transformations: the Hibernate transformation, and
the logging transformation. Unfortunately,
HibernateEntityEnhancer
needs to break the chain of class visitors to be able to call into
the Hibernate Enhancer API. To be able to pretend that it's still
a regular
ClassVisitor
, it serializes the intermediate stateto a
byte[]
, runs the Hibernate enhancer, and then builds a wholenew
ClassReader
to continue in the original chain. This newClassReader
is missing the options set on the originalClassReader
,which causes a failure in the logging transformation, because that
uses
LocalVariablesSorter
.This commit introduces
QuarkusClassVisitor
, a new superclassfor class visitors that require access to some contextual data.
The bytecode transformation machinery puts the
ClassReader
options into each
QuarkusClassVisitor
instance beforethe bytecode transformation process begins. Finally,
HibernateEntityEnhancer
extends this new class, so that whenit creates the new
ClassReader
, it can pass the correct options.Fixes #22157