Skip to content

Commit

Permalink
Merge pull request #40706 from zakkak/2024-05-17-improve-registerforr…
Browse files Browse the repository at this point in the history
…eflection-docs

Improve documentation about `@RegisterForReflection`
  • Loading branch information
geoand authored May 18, 2024
2 parents 6cf3b7e + 0f1840a commit 8658a4f
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 9 deletions.
7 changes: 4 additions & 3 deletions docs/src/main/asciidoc/amqp.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,10 @@ Quarkus has built-in capabilities to deal with JSON AMQP messages.
[NOTE]
.@RegisterForReflection
====
The `@RegisterForReflection` annotation instructs Quarkus to include the class (including fields and methods) when building the native executable.
This will be useful later when we run the applications as native executables inside containers.
Without, the native compilation would remove the fields and methods during the dead-code elimination phase.
The `@RegisterForReflection` annotation instructs Quarkus to keep the class, its fields, and methods when creating a native executable.
This is crucial when we later run our applications as native executables within containers.
Without this annotation, the native compilation process would discard the fields and methods during the dead-code elimination phase, which would lead to runtime errors.
More details about the `@RegisterForReflection` annotation can be found on the xref:writing-native-applications-tips.adoc#registerForReflection[native application tips] page.
====

== Sending quote request
Expand Down
1 change: 1 addition & 0 deletions docs/src/main/asciidoc/cache.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -1075,3 +1075,4 @@ When you encounter this error, you can easily fix it by adding the following ann
<1> It is an array, so you can register several cache implementations in one go if your configuration requires several of them.

This annotation will register the cache implementation classes for reflection and this will include the classes into the native executable.
More details about the `@RegisterForReflection` annotation can be found on the xref:writing-native-applications-tips.adoc#registerForReflection[native application tips] page.
2 changes: 1 addition & 1 deletion docs/src/main/asciidoc/mongodb.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,7 @@ Currently, Quarkus doesn't support link:https://docs.mongodb.com/manual/core/sec
====
If you encounter the following error when running your application in native mode: +
`Failed to encode 'MyObject'. Encoding 'myVariable' errored with: Can't find a codec for class org.acme.MyVariable.` +
This means that the `org.acme.MyVariable` class is not known to GraalVM, the remedy is to add the `@RegisterForReflection` annotation to your `MyVariable class`.
This means that the `org.acme.MyVariable` class is not known to GraalVM, the remedy is to add the `@RegisterForReflection` annotation to your `MyVariable` class.
More details about the `@RegisterForReflection` annotation can be found on the xref:writing-native-applications-tips.adoc#registerForReflection[native application tips] page.
====

Expand Down
2 changes: 1 addition & 1 deletion docs/src/main/asciidoc/qute-reference.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -2538,7 +2538,7 @@ There are several ways to solve this problem:
** In this case, an optimized value resolver is generated automatically and used at runtime
** This is the preferred solution
* Annotate the model class with <<template_data,`@TemplateData`>> - a specialized value resolver is generated and used at runtime
* Annotate the model class with `@io.quarkus.runtime.annotations.RegisterForReflection` to make the reflection-based value resolver work
* Annotate the model class with `@io.quarkus.runtime.annotations.RegisterForReflection` to make the reflection-based value resolver work. More details about the `@RegisterForReflection` annotation can be found on the xref:writing-native-applications-tips.adoc#registerForReflection[native application tips] page.


[[rest_integration]]
Expand Down
7 changes: 4 additions & 3 deletions docs/src/main/asciidoc/rabbitmq.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,10 @@ Quarkus has built-in capabilities to deal with JSON RabbitMQ messages.
[NOTE]
.@RegisterForReflection
====
The `@RegisterForReflection` annotation instructs Quarkus to include the class (including fields and methods) when building the native executable.
This will be useful later when we run the applications as native executables inside containers.
Without, the native compilation would remove the fields and methods during the dead-code elimination phase.
The `@RegisterForReflection` annotation instructs Quarkus to keep the class, its fields, and methods when creating a native executable.
This is crucial when we later run our applications as native executables within containers.
Without this annotation, the native compilation process would discard the fields and methods during the dead-code elimination phase, which would lead to runtime errors.
More details about the `@RegisterForReflection` annotation can be found on the xref:writing-native-applications-tips.adoc#registerForReflection[native application tips] page.
====

== Sending quote request
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -882,7 +882,7 @@ public class MediaLibraryPermission extends LibraryPermission {
}
----
<1> When building a native executable, the permission class must be registered for reflection unless it is also used in at least one `io.quarkus.security.PermissionsAllowed#name` parameter.
<1> When building a native executable, the permission class must be registered for reflection unless it is also used in at least one `io.quarkus.security.PermissionsAllowed#name` parameter. More details about the `@RegisterForReflection` annotation can be found on the xref:writing-native-applications-tips.adoc#registerForReflection[native application tips] page.
<2> We want to pass the `MediaLibrary` instance to the `LibraryPermission` constructor.

[source,properties]
Expand Down
2 changes: 2 additions & 0 deletions docs/src/main/asciidoc/writing-native-applications-tips.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,8 @@ public class MyReflectionConfiguration {
}
----

Note: By default the `@RegisterForReflection` annotation will also registered any potential nested classes for reflection. If you want to avoid this behavior, you can set the `ignoreNested` attribute to `true`.

==== Using a configuration file

You can also use a configuration file to register classes for reflection, if you prefer relying on the GraalVM infrastructure.
Expand Down

0 comments on commit 8658a4f

Please sign in to comment.