@@ -198,6 +198,7 @@ class BeanClass {
198
198
public void setProp1 (String arg ) {}
199
199
public void setProp2 (String arg ) {}
200
200
public void setProp2 (Integer arg ) {}
201
+ public void setProp2 (boolean arg ) {}
201
202
}
202
203
ReflectorFactory reflectorFactory = new DefaultReflectorFactory ();
203
204
Reflector reflector = reflectorFactory .findForClass (BeanClass .class );
@@ -218,9 +219,9 @@ public void setProp2(Integer arg) {}
218
219
Object [] param = String .class .equals (paramType )? new String []{"x" } : new Integer []{1 };
219
220
when (ambiguousInvoker ).invoke (new BeanClass (), param );
220
221
then (caughtException ()).isInstanceOf (ReflectionException .class )
221
- . hasMessageContaining ( "Ambiguous setters defined for property 'prop2' in class '" + BeanClass . class . getName () + "' with types" )
222
- . hasMessageContaining ( "java.lang.String " )
223
- . hasMessageContaining ( " java.lang.Integer" );
222
+ . hasMessageMatching (
223
+ "Ambiguous setters defined for property 'prop2' in class '" + BeanClass . class . getName (). replace ( "$" , " \\ $ " )
224
+ + "' with types '(java.lang.String|java.lang.Integer|boolean)' and '( java.lang.String|java.lang. Integer|boolean)' \\ . " );
224
225
}
225
226
226
227
@ Test
@@ -300,4 +301,25 @@ public void setBool(boolean bool) {}
300
301
Reflector reflector = reflectorFactory .findForClass (Bean .class );
301
302
assertTrue ((Boolean )reflector .getGetInvoker ("bool" ).invoke (new Bean (), new Byte [0 ]));
302
303
}
304
+
305
+ @ Test
306
+ void shouldIgnoreBestMatchSetterIfGetterIsAmbiguous () throws Exception {
307
+ @ SuppressWarnings ("unused" )
308
+ class Bean {
309
+ public Integer isBool () {return Integer .valueOf (1 );}
310
+ public Integer getBool () {return Integer .valueOf (2 );}
311
+ public void setBool (boolean bool ) {}
312
+ public void setBool (Integer bool ) {}
313
+ }
314
+ ReflectorFactory reflectorFactory = new DefaultReflectorFactory ();
315
+ Reflector reflector = reflectorFactory .findForClass (Bean .class );
316
+ Class <?> paramType = reflector .getSetterType ("bool" );
317
+ Object [] param = boolean .class .equals (paramType ) ? new Boolean [] { true } : new Integer [] { 1 };
318
+ Invoker ambiguousInvoker = reflector .getSetInvoker ("bool" );
319
+ when (ambiguousInvoker ).invoke (new Bean (), param );
320
+ then (caughtException ()).isInstanceOf (ReflectionException .class )
321
+ .hasMessageMatching (
322
+ "Ambiguous setters defined for property 'bool' in class '" + Bean .class .getName ().replace ("$" , "\\ $" )
323
+ + "' with types '(java.lang.Integer|boolean)' and '(java.lang.Integer|boolean)'\\ ." );
324
+ }
303
325
}
0 commit comments