@@ -209,37 +209,37 @@ public PropertyDescriptor[] getPropertyDescriptors() {
209
209
210
210
@ Override
211
211
public BeanInfo [] getAdditionalBeanInfo () {
212
- return delegate .getAdditionalBeanInfo ();
212
+ return this . delegate .getAdditionalBeanInfo ();
213
213
}
214
214
215
215
@ Override
216
216
public BeanDescriptor getBeanDescriptor () {
217
- return delegate .getBeanDescriptor ();
217
+ return this . delegate .getBeanDescriptor ();
218
218
}
219
219
220
220
@ Override
221
221
public int getDefaultEventIndex () {
222
- return delegate .getDefaultEventIndex ();
222
+ return this . delegate .getDefaultEventIndex ();
223
223
}
224
224
225
225
@ Override
226
226
public int getDefaultPropertyIndex () {
227
- return delegate .getDefaultPropertyIndex ();
227
+ return this . delegate .getDefaultPropertyIndex ();
228
228
}
229
229
230
230
@ Override
231
231
public EventSetDescriptor [] getEventSetDescriptors () {
232
- return delegate .getEventSetDescriptors ();
232
+ return this . delegate .getEventSetDescriptors ();
233
233
}
234
234
235
235
@ Override
236
236
public Image getIcon (int iconKind ) {
237
- return delegate .getIcon (iconKind );
237
+ return this . delegate .getIcon (iconKind );
238
238
}
239
239
240
240
@ Override
241
241
public MethodDescriptor [] getMethodDescriptors () {
242
- return delegate .getMethodDescriptors ();
242
+ return this . delegate .getMethodDescriptors ();
243
243
}
244
244
}
245
245
@@ -293,7 +293,7 @@ public Class<?> getPropertyType() {
293
293
this .propertyType = findPropertyType (this .readMethod , this .writeMethod );
294
294
}
295
295
catch (IntrospectionException ex ) {
296
- // ignore , as does PropertyDescriptor#getPropertyType
296
+ // Ignore , as does PropertyDescriptor#getPropertyType
297
297
}
298
298
}
299
299
return this .propertyType ;
@@ -383,7 +383,7 @@ public Class<?> getPropertyType() {
383
383
this .propertyType = findPropertyType (this .readMethod , this .writeMethod );
384
384
}
385
385
catch (IntrospectionException ex ) {
386
- // ignore , as does IndexedPropertyDescriptor#getPropertyType
386
+ // Ignore , as does IndexedPropertyDescriptor#getPropertyType
387
387
}
388
388
}
389
389
return this .propertyType ;
@@ -417,7 +417,7 @@ public Class<?> getIndexedPropertyType() {
417
417
getName (), getPropertyType (), this .indexedReadMethod , this .indexedWriteMethod );
418
418
}
419
419
catch (IntrospectionException ex ) {
420
- // ignore , as does IndexedPropertyDescriptor#getIndexedPropertyType
420
+ // Ignore , as does IndexedPropertyDescriptor#getIndexedPropertyType
421
421
}
422
422
}
423
423
return this .indexedPropertyType ;
@@ -482,14 +482,14 @@ public static void copyNonMethodProperties(PropertyDescriptor source, PropertyDe
482
482
target .setShortDescription (source .getShortDescription ());
483
483
target .setDisplayName (source .getDisplayName ());
484
484
485
- // copy all attributes (emulating behavior of private FeatureDescriptor#addTable)
485
+ // Copy all attributes (emulating behavior of private FeatureDescriptor#addTable)
486
486
Enumeration <String > keys = source .attributeNames ();
487
487
while (keys .hasMoreElements ()) {
488
488
String key = keys .nextElement ();
489
489
target .setValue (key , source .getValue (key ));
490
490
}
491
491
492
- // see java.beans.PropertyDescriptor#PropertyDescriptor(PropertyDescriptor)
492
+ // See java.beans.PropertyDescriptor#PropertyDescriptor(PropertyDescriptor)
493
493
target .setPropertyEditorClass (source .getPropertyEditorClass ());
494
494
target .setBound (source .isBound ());
495
495
target .setConstrained (source .isConstrained ());
@@ -503,24 +503,34 @@ public static Class<?> findPropertyType(Method readMethod, Method writeMethod) t
503
503
if (readMethod != null ) {
504
504
Class <?>[] params = readMethod .getParameterTypes ();
505
505
if (params .length != 0 ) {
506
- throw new IntrospectionException ("bad read method arg count: " + readMethod );
506
+ throw new IntrospectionException ("Bad read method arg count: " + readMethod );
507
507
}
508
508
propertyType = readMethod .getReturnType ();
509
509
if (propertyType == Void .TYPE ) {
510
- throw new IntrospectionException ("read method "
511
- + readMethod .getName () + " returns void" );
510
+ throw new IntrospectionException ("Read method returns void: " + readMethod );
512
511
}
513
512
}
514
513
if (writeMethod != null ) {
515
514
Class <?> params [] = writeMethod .getParameterTypes ();
516
515
if (params .length != 1 ) {
517
- throw new IntrospectionException ("bad write method arg count: " + writeMethod );
516
+ throw new IntrospectionException ("Bad write method arg count: " + writeMethod );
518
517
}
519
- if (propertyType != null
520
- && !params [0 ].isAssignableFrom (propertyType )) {
521
- throw new IntrospectionException ("type mismatch between read and write methods" );
518
+ if (propertyType != null ) {
519
+ if (propertyType .isAssignableFrom (params [0 ])) {
520
+ // Write method's property type potentially more specific
521
+ propertyType = params [0 ];
522
+ }
523
+ else if (params [0 ].isAssignableFrom (propertyType )) {
524
+ // Proceed with read method's property type
525
+ }
526
+ else {
527
+ throw new IntrospectionException (
528
+ "Type mismatch between read and write methods: " + readMethod + " - " + writeMethod );
529
+ }
530
+ }
531
+ else {
532
+ propertyType = params [0 ];
522
533
}
523
- propertyType = params [0 ];
524
534
}
525
535
return propertyType ;
526
536
}
@@ -532,44 +542,48 @@ public static Class<?> findIndexedPropertyType(String name, Class<?> propertyTyp
532
542
Method indexedReadMethod , Method indexedWriteMethod ) throws IntrospectionException {
533
543
534
544
Class <?> indexedPropertyType = null ;
535
-
536
545
if (indexedReadMethod != null ) {
537
546
Class <?> params [] = indexedReadMethod .getParameterTypes ();
538
547
if (params .length != 1 ) {
539
- throw new IntrospectionException (
540
- "bad indexed read method arg count" );
548
+ throw new IntrospectionException ("Bad indexed read method arg count: " + indexedReadMethod );
541
549
}
542
550
if (params [0 ] != Integer .TYPE ) {
543
- throw new IntrospectionException (
544
- "non int index to indexed read method" );
551
+ throw new IntrospectionException ("Non int index to indexed read method: " + indexedReadMethod );
545
552
}
546
553
indexedPropertyType = indexedReadMethod .getReturnType ();
547
554
if (indexedPropertyType == Void .TYPE ) {
548
- throw new IntrospectionException (
549
- "indexed read method returns void" );
555
+ throw new IntrospectionException ("Indexed read method returns void: " + indexedReadMethod );
550
556
}
551
557
}
552
558
if (indexedWriteMethod != null ) {
553
559
Class <?> params [] = indexedWriteMethod .getParameterTypes ();
554
560
if (params .length != 2 ) {
555
- throw new IntrospectionException (
556
- "bad indexed write method arg count" );
561
+ throw new IntrospectionException ("Bad indexed write method arg count: " + indexedWriteMethod );
557
562
}
558
563
if (params [0 ] != Integer .TYPE ) {
559
- throw new IntrospectionException (
560
- "non int index to indexed write method" );
564
+ throw new IntrospectionException ("Non int index to indexed write method: " + indexedWriteMethod );
561
565
}
562
- if (indexedPropertyType != null && indexedPropertyType != params [1 ]) {
563
- throw new IntrospectionException (
564
- "type mismatch between indexed read and indexed write methods: " + name );
566
+ if (indexedPropertyType != null ) {
567
+ if (indexedPropertyType .isAssignableFrom (params [1 ])) {
568
+ // Write method's property type potentially more specific
569
+ indexedPropertyType = params [1 ];
570
+ }
571
+ else if (params [1 ].isAssignableFrom (indexedPropertyType )) {
572
+ // Proceed with read method's property type
573
+ }
574
+ else {
575
+ throw new IntrospectionException ("Type mismatch between indexed read and write methods: " +
576
+ indexedReadMethod + " - " + indexedWriteMethod );
577
+ }
578
+ }
579
+ else {
580
+ indexedPropertyType = params [1 ];
565
581
}
566
- indexedPropertyType = params [1 ];
567
582
}
568
- if (propertyType != null
569
- && (!propertyType .isArray () ||
570
- propertyType .getComponentType () != indexedPropertyType )) {
571
- throw new IntrospectionException (
572
- "type mismatch between indexed and non-indexed methods: " + name );
583
+ if (propertyType != null && (!propertyType .isArray () ||
584
+ propertyType .getComponentType () != indexedPropertyType )) {
585
+ throw new IntrospectionException ("Type mismatch between indexed and non-indexed methods: " +
586
+ indexedReadMethod + " - " + indexedWriteMethod );
573
587
}
574
588
return indexedPropertyType ;
575
589
}
@@ -590,15 +604,12 @@ public static boolean equals(PropertyDescriptor pd1, Object obj) {
590
604
if (!compareMethods (pd1 .getReadMethod (), pd2 .getReadMethod ())) {
591
605
return false ;
592
606
}
593
-
594
607
if (!compareMethods (pd1 .getWriteMethod (), pd2 .getWriteMethod ())) {
595
608
return false ;
596
609
}
597
-
598
- if (pd1 .getPropertyType () == pd2 .getPropertyType ()
599
- && pd1 .getPropertyEditorClass () == pd2 .getPropertyEditorClass ()
600
- && pd1 .isBound () == pd2 .isBound ()
601
- && pd1 .isConstrained () == pd2 .isConstrained ()) {
610
+ if (pd1 .getPropertyType () == pd2 .getPropertyType () &&
611
+ pd1 .getPropertyEditorClass () == pd2 .getPropertyEditorClass () &&
612
+ pd1 .isBound () == pd2 .isBound () && pd1 .isConstrained () == pd2 .isConstrained ()) {
602
613
return true ;
603
614
}
604
615
}
@@ -612,7 +623,7 @@ public static boolean compareMethods(Method a, Method b) {
612
623
if ((a == null ) != (b == null )) {
613
624
return false ;
614
625
}
615
- if (a != null && b != null ) {
626
+ if (a != null ) {
616
627
if (!a .equals (b )) {
617
628
return false ;
618
629
}
0 commit comments