Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

There is a compatibility problem of DubboHeadersGetter#keys in Dubbo 2.7.6 and 2.7.7 #12978

Open
steverao opened this issue Dec 30, 2024 · 4 comments · May be fixed by #12982
Open

There is a compatibility problem of DubboHeadersGetter#keys in Dubbo 2.7.6 and 2.7.7 #12978

steverao opened this issue Dec 30, 2024 · 4 comments · May be fixed by #12982
Assignees
Labels
bug Something isn't working

Comments

@steverao
Copy link
Contributor

steverao commented Dec 30, 2024

Describe the bug

In Dubbo instrumentation, I found a compatibility problem of DubboHeadersGetter#keys in Dubbo 2.7.6, 2.7.7.
In related versions, the getAttachments is as follows:

@Deprecated
@Override
public Map<String, String> getAttachments() {
    return new AttachmentsAdapter.ObjectToStringMap(attachments);
}

public static class ObjectToStringMap extends HashMap<String, String> {
        private Map<String, Object> attachments;

        public ObjectToStringMap(Map<String, Object> attachments) {
            this.attachments = attachments;
        }

        @Override
        public String get(Object key) {
            Object obj = attachments.get(key);
            return convert(obj);
        }

        @Override
        public String put(String key, String value) {
            Object obj = attachments.put(key, value);
            return convert(obj);
        }

        @Override
        public String remove(Object key) {
            Object obj = attachments.remove(key);
            return convert(obj);
        }

        private String convert(Object obj) {
            if (obj instanceof String) {
                return (String) obj;
            }
            return null; // or JSON.toString(obj);
        }
    }

The ObjectToStringMap can't get all keySet by keySet method, so it can't get correct result of DubboHeadersGetter#keys in related version.

Steps to reproduce

We can compare the codes between Dubbo 2.7.6, 2.7.7 and others, we can get above conclusion by codes.

Expected behavior

DubboHeadersGetter#keys can't get correct result in Dubbo 2.7.6, 2.7.7

Actual behavior

DubboHeadersGetter#keys can get correct result in Dubbo 2.7.6, 2.7.7

Javaagent or library instrumentation version

2.11.0

Environment

No response

Additional context

No response

@steverao steverao added the bug Something isn't working label Dec 30, 2024
@steverao steverao self-assigned this Dec 30, 2024
@laurit
Copy link
Contributor

laurit commented Jan 2, 2025

The ObjectToStringMap doesn't contain keySet method, so it can't get correct result of DubboHeadersGetter#keys in related version.

I don't get this. ObjectToStringMap extends HashMap that has keySet method. Elements added by super.put that is called in the constructor of ObjectToStringMap should be in that set. The implementation for ObjectToStringMap is different for versions 2.7.6 and 2.7.7 where super.put is not called in the constructor for ObjectToStringMap.

@steverao
Copy link
Contributor Author

steverao commented Jan 2, 2025

I don't get this. ObjectToStringMap extends HashMap that has keySet method. Elements added by super.put that is called in the constructor of ObjectToStringMap should be in that set. The implementation for ObjectToStringMap is different for versions 2.7.6 and 2.7.7 where super.put is not called in the constructor for ObjectToStringMap.

Yes, as your said, there are something wrong in previous description, I have corrected them.

@laurit
Copy link
Contributor

laurit commented Jan 2, 2025

Yes, as your said, there are something wrong in previous description, I have corrected them.

I think the title of the issue could also be changed to indicate that the issue is present only in a specific versions. Currently it leaves an impression that there is a problem in all versions later and including 2.7.6.

@steverao steverao changed the title There is a compatibility problem of DubboHeadersGetter#keys in Dubbo 2.7.6+ There is a compatibility problem of DubboHeadersGetter#keys in Dubbo 2.7.6 and 2.7.7 Jan 2, 2025
@steverao
Copy link
Contributor Author

steverao commented Jan 2, 2025

I think the title of the issue could also be changed to indicate that the issue is present only in a specific versions. Currently it leaves an impression that there is a problem in all versions later and including 2.7.6.

Sure, done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
2 participants