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

Fix logging with panache in entities #22734

Merged
merged 1 commit into from
Jan 7, 2022

Conversation

Ladicek
Copy link
Contributor

@Ladicek Ladicek commented Jan 7, 2022

In case an entity class uses io.quarkus.logging.Log, it requires
two 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 state
to a byte[], runs the Hibernate enhancer, and then builds a whole
new ClassReader to continue in the original chain. This new
ClassReader is missing the options set on the original ClassReader,
which causes a failure in the logging transformation, because that
uses LocalVariablesSorter.

This commit introduces QuarkusClassVisitor, a new superclass
for class visitors that require access to some contextual data.
The bytecode transformation machinery puts the ClassReader
options into each QuarkusClassVisitor instance before
the bytecode transformation process begins. Finally,
HibernateEntityEnhancer extends this new class, so that when
it creates the new ClassReader, it can pass the correct options.

Fixes #22157

In case an entity class uses `io.quarkus.logging.Log`, it requires
two 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 state
to a `byte[]`, runs the Hibernate enhancer, and then builds a whole
new `ClassReader` to continue in the original chain. This new
`ClassReader` is missing the options set on the original `ClassReader`,
which causes a failure in the logging transformation, because that
uses `LocalVariablesSorter`.

This commit introduces `QuarkusClassVisitor`, a new superclass
for class visitors that require access to some contextual data.
The bytecode transformation machinery puts the `ClassReader`
options into each `QuarkusClassVisitor` instance before
the bytecode transformation process begins. Finally,
`HibernateEntityEnhancer` extends this new class, so that when
it creates the new `ClassReader`, it can pass the correct options.
Copy link
Contributor

@gastaldi gastaldi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

@gsmet gsmet merged commit 94303fe into quarkusio:main Jan 7, 2022
@quarkus-bot quarkus-bot bot added this to the 2.7 - main milestone Jan 7, 2022
@gsmet gsmet modified the milestones: 2.7 - main, 2.6.2.Final Jan 8, 2022
@Ladicek Ladicek deleted the logging-with-panache-in-entities branch January 10, 2022 07:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/core area/hibernate-orm Hibernate ORM area/persistence OBSOLETE, DO NOT USE
Projects
None yet
Development

Successfully merging this pull request may close these issues.

LocalVariablesSorter only accepts expanded frames error when using Quarkus Log in Panache entities
3 participants