@@ -196,6 +196,7 @@ public void addProperty(SettableBeanProperty prop)
196
196
* currently built bean.
197
197
*/
198
198
public void addBackReferenceProperty (String referenceName , SettableBeanProperty prop )
199
+ throws JsonMappingException
199
200
{
200
201
if (_backRefProperties == null ) {
201
202
_backRefProperties = new HashMap <String , SettableBeanProperty >(4 );
@@ -204,7 +205,11 @@ public void addBackReferenceProperty(String referenceName, SettableBeanProperty
204
205
// NOT work (2 failing unit tests). Not 100% clear why, but for now force
205
206
// access set early; unfortunate, but since it works....
206
207
if (_config .canOverrideAccessModifiers ()) {
207
- prop .fixAccess (_config );
208
+ try {
209
+ prop .fixAccess (_config );
210
+ } catch (IllegalArgumentException e ) {
211
+ _handleBadAccess (e );
212
+ }
208
213
}
209
214
_backRefProperties .put (referenceName , prop );
210
215
// 16-Jan-2018, tatu: As per [databind#1878] we may want to leave it as is, to allow
@@ -221,12 +226,17 @@ public void addBackReferenceProperty(String referenceName, SettableBeanProperty
221
226
public void addInjectable (PropertyName propName , JavaType propType ,
222
227
Annotations contextAnnotations , AnnotatedMember member ,
223
228
Object valueId )
229
+ throws JsonMappingException
224
230
{
225
231
if (_injectables == null ) {
226
232
_injectables = new ArrayList <ValueInjector >();
227
233
}
228
234
if ( _config .canOverrideAccessModifiers ()) {
229
- member .fixAccess (_config .isEnabled (MapperFeature .OVERRIDE_PUBLIC_ACCESS_MODIFIERS ));
235
+ try {
236
+ member .fixAccess (_config .isEnabled (MapperFeature .OVERRIDE_PUBLIC_ACCESS_MODIFIERS ));
237
+ } catch (IllegalArgumentException e ) {
238
+ _handleBadAccess (e );
239
+ }
230
240
}
231
241
_injectables .add (new ValueInjector (propName , propType , member , valueId ));
232
242
}
@@ -368,6 +378,7 @@ public boolean hasIgnorable(String name) {
368
378
* information collected.
369
379
*/
370
380
public JsonDeserializer <?> build ()
381
+ throws JsonMappingException
371
382
{
372
383
Collection <SettableBeanProperty > props = _properties .values ();
373
384
_fixAccess (props );
@@ -494,6 +505,7 @@ protected JsonDeserializer<?> createBuilderBasedDeserializer(JavaType valueType,
494
505
*/
495
506
496
507
protected void _fixAccess (Collection <SettableBeanProperty > mainProps )
508
+ throws JsonMappingException
497
509
{
498
510
/* 07-Sep-2016, tatu: Ideally we should be able to avoid forcing
499
511
* access to properties that are likely ignored, but due to
@@ -519,7 +531,11 @@ protected void _fixAccess(Collection<SettableBeanProperty> mainProps)
519
531
continue;
520
532
}
521
533
*/
522
- prop .fixAccess (_config );
534
+ try {
535
+ prop .fixAccess (_config );
536
+ } catch (IllegalArgumentException e ) {
537
+ _handleBadAccess (e );
538
+ }
523
539
}
524
540
}
525
541
@@ -528,7 +544,11 @@ protected void _fixAccess(Collection<SettableBeanProperty> mainProps)
528
544
/*
529
545
if (_backRefProperties != null) {
530
546
for (SettableBeanProperty prop : _backRefProperties.values()) {
531
- prop.fixAccess(_config);
547
+ try {
548
+ prop.fixAccess(_config);
549
+ } catch (IllegalArgumentException e) {
550
+ _handleBadAccess(e);
551
+ }
532
552
}
533
553
}
534
554
*/
@@ -538,10 +558,18 @@ protected void _fixAccess(Collection<SettableBeanProperty> mainProps)
538
558
// be left as-is? May reconsider based on feedback
539
559
540
560
if (_anySetter != null ) {
541
- _anySetter .fixAccess (_config );
561
+ try {
562
+ _anySetter .fixAccess (_config );
563
+ } catch (IllegalArgumentException e ) {
564
+ _handleBadAccess (e );
565
+ }
542
566
}
543
567
if (_buildMethod != null ) {
544
- _buildMethod .fixAccess (_config .isEnabled (MapperFeature .OVERRIDE_PUBLIC_ACCESS_MODIFIERS ));
568
+ try {
569
+ _buildMethod .fixAccess (_config .isEnabled (MapperFeature .OVERRIDE_PUBLIC_ACCESS_MODIFIERS ));
570
+ } catch (IllegalArgumentException e ) {
571
+ _handleBadAccess (e );
572
+ }
545
573
}
546
574
}
547
575
@@ -577,4 +605,24 @@ protected boolean _findCaseInsensitivity() {
577
605
return (B == null ) ? _config .isEnabled (MapperFeature .ACCEPT_CASE_INSENSITIVE_PROPERTIES )
578
606
: B .booleanValue ();
579
607
}
608
+
609
+ /**
610
+ * Helper method for linking root cause to "invalid type definition" exception;
611
+ * needed for troubleshooting issues with forcing access on later JDKs
612
+ * (as module definition boundaries are more strictly enforced).
613
+ *
614
+ * @since 2.13.2
615
+ */
616
+ protected void _handleBadAccess (IllegalArgumentException e0 )
617
+ throws JsonMappingException
618
+ {
619
+ try {
620
+ _context .reportBadTypeDefinition (_beanDesc , e0 .getMessage ());
621
+ } catch (DatabindException e ) {
622
+ if (e .getCause () == null ) {
623
+ e .initCause (e0 );
624
+ }
625
+ throw e ;
626
+ }
627
+ }
580
628
}
0 commit comments