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

putFields field gets overwritten for every field #136

Closed
pzygielo opened this issue Nov 23, 2022 · 1 comment · Fixed by #134
Closed

putFields field gets overwritten for every field #136

pzygielo opened this issue Nov 23, 2022 · 1 comment · Fixed by #134

Comments

@pzygielo
Copy link
Contributor

pzygielo commented Nov 23, 2022

@Override
public ObjectOutputStream.PutField putFields()
throws IOException {
putFields = new HookPutFields();
return putFields;
}

Thus - if class defines few fields AND in its writeObject methods registers each one with separate outStream.putFields().put(...) - like ConcurrentHashMap (JDK8) does:
https://github.com/openjdk/jdk/blob/9a9add8825a040565051a09010b29b099c2e7d49/jdk/src/share/classes/java/util/concurrent/ConcurrentHashMap.java#L1403-L1405
then only one field is serialized with value, and the remaining are serialized as nulls in (example for int):

case 'I':
if (value == null) {
orbStream.write_long(0);
} else {
orbStream.write_long(((Integer) value).intValue());
}
break;

But due to putFields being overwritten - fields at

Object value = fields.get(osfields[i].getName());

is new, one-element only map, for every new field put to the stream.

@pzygielo pzygielo changed the title fields field gets overwritten for every field putFields field gets overwritten for every field Nov 23, 2022
@pzygielo
Copy link
Contributor Author

JDK-8075802

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant