You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@ignite.apache.org by "Sergey Uttsel (Jira)" <ji...@apache.org> on 2023/05/08 07:07:00 UTC

[jira] [Comment Edited] (IGNITE-19183) IgniteToStringBuilder#toString(java.lang.Class, T) do not properly print inherited classes

    [ https://issues.apache.org/jira/browse/IGNITE-19183?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17720412#comment-17720412 ] 

Sergey Uttsel edited comment on IGNITE-19183 at 5/8/23 7:06 AM:
----------------------------------------------------------------

I see org.apache.ignite.internal.cluster.management.topology.api.LogicalNode#toString is marked with TODO IGNITE-19183
 
We have {{{}LogicalNode extends ClusterNode{}}}.

 
{code:java}
class ClusterNode {
    private final String id;
    private final String name;
    private final NetworkAddress address;
    private final NodeMetadata nodeMetadata;
    public String toString() {
        return S.toString(ClusterNode.class, this);
    }
}
class LogicalNode extends ClusterNode {
    private final Map<String, String> nodeAttributes;
    public String toString() {
        return S.toString(LogicalNode.class, this);
    }
}
{code}
toString on a LogicalNode instance prints:
{noformat}
LogicalNode []{noformat}
It's expected behavior.
 
If I change toString in LogicalNode to:
{code:java}
public String toString() {
    return S.toString(LogicalNode.class, this, super.toString());
}{code}
then toString prints: 
{noformat}
LogicalNode [super=ClusterNode [id=qqq, name=www, address=zzz:111, nodeMetadata=null]]{noformat}
It's expected behavior.
 
If I add annotation _@IgniteToStringInclude_ on
{noformat}
private final Map<String, String> nodeAttributes;{noformat}
then toString prints:
{noformat}
LogicalNode [nodeAttributes=EmptyMap {}, super=ClusterNode [id=qqq, name=www, address=zzz:111, nodeMetadata=null]]{noformat}
It's expected behavior because by default a Map implementation is excluded.
See IgniteToStringBuilder java doc. Ignite2 has the same rules.


was (Author: sergey uttsel):
I see org.apache.ignite.internal.cluster.management.topology.api.LogicalNode#toString is marked with TODO IGNITE-19183
 
We have {{{}LogicalNode extends ClusterNode{}}}.
class ClusterNode \{
    private final String id;

    private final String name;

    private final NetworkAddress address;

    private final NodeMetadata nodeMetadata;

    public String toString() {
        return S.toString(ClusterNode.class, this);
    }
}

classd LogicalNode extends ClusterNode \{
    private final Map<String, String> nodeAttributes;

    public String toString() {
        return S.toString(LogicalNode.class, this);
    }
}
 
toString on a LogicalNode instance prints:
{noformat}
LogicalNode []{noformat}
{{{}{}}}It's expected behavior.
 
If I change toString in LogicalNode to:
    public String toString() \{
            return S.toString(LogicalNode.class, this, super.toString());
        }
then toString prints: 
{noformat}
LogicalNode [super=ClusterNode [id=qqq, name=www, address=zzz:111, nodeMetadata=null]]{noformat}
It's expected behavior.
 
If I add annotation _@IgniteToStringInclude_ on
{noformat}
private final Map<String, String> nodeAttributes;{noformat}
{{{}{}}}field then toString prints:
{noformat}
LogicalNode [nodeAttributes=EmptyMap {}, super=ClusterNode [id=qqq, name=www, address=zzz:111, nodeMetadata=null]]{noformat}
{{{}{}}}It's expected behavior because by default a Map implementation is excluded.
See IgniteToStringBuilder java doc. Ignite2 has the same rules.

> IgniteToStringBuilder#toString(java.lang.Class<T>, T) do not properly print inherited classes
> ---------------------------------------------------------------------------------------------
>
>                 Key: IGNITE-19183
>                 URL: https://issues.apache.org/jira/browse/IGNITE-19183
>             Project: Ignite
>          Issue Type: Bug
>            Reporter: Mirza Aliev
>            Priority: Major
>              Labels: ignite-3
>
> {*}Expected behaviour{*}:
> {code:java}
> class A {
>    int f1;
> }
> class B extend A {
>   int f2;
> }
> {code}
> {{S.toString(B.class, this);}} will return "B [f1 = x, f2 = y]"
> {*}Actual behaviour{*}:
> {{S.toString(B.class, this);}} returns "B []"



--
This message was sent by Atlassian Jira
(v8.20.10#820010)