@@ -43,41 +43,43 @@ public BeanDeserializerBuilder updateBuilder(DeserializationConfig config,
4343 BeanDescription .Supplier beanDescRef , BeanDeserializerBuilder builder )
4444 {
4545 final Class <?> beanClass = beanDescRef .getBeanClass ();
46- // [module-afterburner#21]: Can't force access to sealed packages, or anything within "java."
47- if (!MyClassLoader .canAddClassInPackageOf (beanClass )) {
48- return builder ;
49- }
50- /* Hmmh. Can we access stuff from private classes?
51- * Possibly, if we can use parent class loader.
52- * (should probably skip all non-public?)
53- */
54- if (_classLoader != null ) {
55- if (Modifier .isPrivate (beanClass .getModifiers ())) {
56- return builder ;
57- }
58- }
59- PropertyMutatorCollector collector = new PropertyMutatorCollector (beanClass );
60- List <OptimizedSettableBeanProperty <?>> newProps = findOptimizableProperties (
61- config , collector , builder .getProperties ());
62- // and if we found any, create mutator proxy, replace property objects
63- if (!newProps .isEmpty ()) {
64- BeanPropertyMutator baseMutator = collector .buildMutator (_classLoader );
65- for (OptimizedSettableBeanProperty <?> prop : newProps ) {
66- builder .addOrReplaceProperty (prop .withMutator (baseMutator ), true );
46+ // Mutator/creator bytecode injection requires being able to define a class
47+ // in the target's package. [module-afterburner#21] rules out sealed packages
48+ // (which in 3.x also covers every package in a named JPMS module) and core
49+ // "java.*" / "sun.misc" / etc. Also: private classes are unreachable when
50+ // using our own classloader rather than the target's.
51+ //
52+ // Note: the SuperSonic deserializer wrapping below is independent of bytecode
53+ // injection — it reuses whichever `SettableBeanProperty` instances the builder
54+ // holds, optimized or not — so we still apply it even when injection is
55+ // disallowed. This lets JPMS users benefit from the ordered-property fast
56+ // path even though afterburner can't inject mutators into their modules.
57+ final boolean canInject = MyClassLoader .canAddClassInPackageOf (beanClass )
58+ && !(_classLoader != null && Modifier .isPrivate (beanClass .getModifiers ()));
59+
60+ if (canInject ) {
61+ PropertyMutatorCollector collector = new PropertyMutatorCollector (beanClass );
62+ List <OptimizedSettableBeanProperty <?>> newProps = findOptimizableProperties (
63+ config , collector , builder .getProperties ());
64+ // and if we found any, create mutator proxy, replace property objects
65+ if (!newProps .isEmpty ()) {
66+ BeanPropertyMutator baseMutator = collector .buildMutator (_classLoader );
67+ for (OptimizedSettableBeanProperty <?> prop : newProps ) {
68+ builder .addOrReplaceProperty (prop .withMutator (baseMutator ), true );
69+ }
6770 }
68- }
69- // Second thing: see if we could (re)generate Creator(s):
70- ValueInstantiator inst = builder .getValueInstantiator ();
71- /* Hmmh. Probably better to require exact default implementation
72- * and not sub-class; chances are sub-class uses its own
73- * construction anyway.
74- */
75- if (inst .getClass () == StdValueInstantiator .class ) {
76- // also, only override if using default creator (no-arg ctor, no-arg static factory)
77- if (inst .canCreateUsingDefault ()) {
78- inst = new CreatorOptimizer (beanClass , _classLoader , (StdValueInstantiator ) inst ).createOptimized ();
79- if (inst != null ) {
80- builder .setValueInstantiator (inst );
71+ // Second thing: see if we could (re)generate Creator(s):
72+ ValueInstantiator inst = builder .getValueInstantiator ();
73+ // Hmmh. Probably better to require exact default implementation
74+ // and not sub-class; chances are sub-class uses its own
75+ // construction anyway.
76+ if (inst .getClass () == StdValueInstantiator .class ) {
77+ // also, only override if using default creator (no-arg ctor, no-arg static factory)
78+ if (inst .canCreateUsingDefault ()) {
79+ inst = new CreatorOptimizer (beanClass , _classLoader , (StdValueInstantiator ) inst ).createOptimized ();
80+ if (inst != null ) {
81+ builder .setValueInstantiator (inst );
82+ }
8183 }
8284 }
8385 }
0 commit comments