Nikolay,

It seems to me, that the real cause of the issue is a contract:

public <T> T getField(String name);

Which can lead to class cast to any type. Consequently, a user gets
runtime type checks instead of compile time checks.

On the other hand, your proposal could be handy in practice, have
nothing against it.

пт, 6 дек. 2019 г. в 13:17, Николай Ижиков <nizhi...@apache.org>:
>
> Hello, Igniters.
>
> We have confusing API in `BinaryObjectBuilder` class.
>
> The code below leads to the `ClassCastException`
> The cause is java method resolution rules [1]
>
> > There may be more than one such method, in which case the most specific one 
> > is chosen
>
> I suggest to deprecate `setField(String name, @Nullable BinaryObjectBuilder 
> builder);` method and introduce
> `setBinaryField(String name, @Nullable BinaryObjectBuilder builder);` instead 
> of it.
>
> What do you think?
>
> ```
> public class BugTest extends GridCommonAbstractTest {
>     @Test public void testBinaryObject() throws Exception {
>         try (Ignite ignite = startGrid(0)) {
>             BinaryObjectBuilder builder = ignite.binary().builder("testVal")
>                 .setField("name", "John Doe", String.class);
>
>             builder.setField("name", builder.getField("name"));
>         }
>     }
> }
> ```
>
> [1] https://docs.oracle.com/javase/specs/jls/se11/html/jls-15.html#jls-15.12.2



-- 
Best regards,
Ivan Pavlukhin

Reply via email to