Class ReflectionIntrospectionPolicy
BeanIntrospector may describe reflectively when it has
no generated introspection for them.
Reading a class back is what the framework is built to avoid, and a reflective introspection exposes every
member of a class to whatever asks for it, so no type is allowed until an application says so. A type is
allowed when its name matches one of the patterns of the "micronaut.introspection.allow-reflection" property, set
either as a system property or in the application configuration, or one of the patterns
allowed programmatically. A pattern is a class name where * stands for
any sequence of characters, matched against the whole name: com.example.model.* allows the classes of
a package and of its sub packages, and only those - com.example.modelling.Order is not one of them -
com.example.Order allows one class, *.Order every class of that name and * every
class.
The policy guards only the fallback of the shared introspector. Code that reflects on a type explicitly -
ReflectionBeanIntrospection.of(Class), ReflectionBeanIntrospector - is not subject to it: that
code made its choice.
- Since:
- 5.2.0
- Author:
- Denis Stepanov
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceThe patterns oneconfigure(Collection)call contributed, which closing takes back. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe property listing the patterns of the types the shared introspector may describe reflectively. -
Method Summary
Modifier and TypeMethodDescriptionstatic voidAllows the types matching the patterns, in addition to the ones already allowed.static voidallow(Collection<String> patterns) Allows the types matching the patterns, in addition to the ones already allowed.static voidAllows the types a predicate accepts, in addition to the ones already allowed.configure(Collection<String> patterns) Contributes the patterns an application configuration allows, in addition to the patterns the other contributions, the system property and the programmatically allowed types allow.configure(Collection<String> patterns, AnnotationMetadata description) Contributes the patterns an application configuration allows together with the annotations it means the types matching them to carry, asconfigure(Collection)contributes the patterns alone.static AnnotationMetadataThe annotations an application configured for a type: theIntrospectedmembers it means the reflective description of the type to be built with, out of the contributions whose patterns the type matches.static booleanWhether a type is allowed.static voidreset()Forgets everything configured and allowed: the patterns of every contribution, whether or not the configuration that contributed them is still running, and every programmatically allowed type.static longversion()The version of what is configured, which changes whenever a contribution is made or taken back or a predicate is allowed.
-
Field Details
-
PROPERTY_ALLOW_REFLECTION
The property listing the patterns of the types the shared introspector may describe reflectively.- See Also:
-
-
Method Details
-
version
public static long version()The version of what is configured, which changes whenever a contribution is made or taken back or a predicate is allowed. A caller caching whatdescribe(Class)answered holds the version it answered at, and asks again once the version has moved.- Returns:
- The version
-
describe
The annotations an application configured for a type: theIntrospectedmembers it means the reflective description of the type to be built with, out of the contributions whose patterns the type matches. Where two contributions describe the same type, the one contributed first wins on the members it sets, and the other still supplies the members it does not.- Parameters:
type- The type- Returns:
- The annotations,
AnnotationMetadata.EMPTY_METADATAwhen nothing is configured for the type
-
isAllowed
Whether a type is allowed.- Parameters:
type- The type- Returns:
- Whether the shared introspector may describe the type reflectively
-
allow
Allows the types matching the patterns, in addition to the ones already allowed.- Parameters:
patterns- The patterns
-
allow
Allows the types matching the patterns, in addition to the ones already allowed.- Parameters:
patterns- The patterns
-
allow
-
configure
Contributes the patterns an application configuration allows, in addition to the patterns the other contributions, the system property and the programmatically allowed types allow. A contribution is not a replacement: the contexts running at the same time in one JVM each contribute their own patterns, and a context takes back exactly the patterns it contributed by closing the registration it was given.- Parameters:
patterns- The patterns- Returns:
- The registration of these patterns, to close when the configuration that contributed them goes away
-
configure
public static ReflectionIntrospectionPolicy.Registration configure(Collection<String> patterns, AnnotationMetadata description) Contributes the patterns an application configuration allows together with the annotations it means the types matching them to carry, asconfigure(Collection)contributes the patterns alone. The annotations are theIntrospectedmembers the reflective description of such a type is built with, which is how a type that cannot be annotated - one of a library, one compiled without the processor - is described the way the application means it to be.- Parameters:
patterns- The patternsdescription- The annotations the matching types carry, empty to contribute the patterns alone- Returns:
- The registration of this contribution, to close when the configuration that made it goes away
-
reset
public static void reset()Forgets everything configured and allowed: the patterns of every contribution, whether or not the configuration that contributed them is still running, and every programmatically allowed type. The system property still applies, as it is not something that can be taken back.
-