waterWang opened a new pull request, #16435:
URL: https://github.com/apache/dubbo/pull/16435
## What is the purpose of the change
Fixes #16432: `JavaBeanSerializeUtil.serialize()` throws
`IllegalArgumentException("Property name is null")` when serializing a `Map`
that contains a `null` key.
`HashMap` permits exactly one `null` key, so this is a legal input. The Map
branch in `serializeInternal` explicitly handles null keys (`key == null ? null
: createDescriptorIfAbsent(...)`), but the descriptor produced is then rejected
by the `notNull` check in `JavaBeanDescriptor.setProperty()`.
## Root cause
In `JavaBeanSerializeUtil.serializeInternal()` Map branch:
```java
map.forEach((key, value) -> {
Object keyDescriptor = key == null ? null :
createDescriptorIfAbsent(key, accessor, cache);
Object valueDescriptor = value == null ? null :
createDescriptorIfAbsent(value, accessor, cache);
descriptor.setProperty(keyDescriptor, valueDescriptor);
});
```
When the map has a null key, `keyDescriptor` is `null`, and
`JavaBeanDescriptor.setProperty(null, value)` throws because of the
`notNull(propertyName, "Property name is null")` guard.
## Fix
Relax the `notNull` guard in `JavaBeanDescriptor.setProperty()` for map-type
descriptors only — a `null` key is a legal Map key and `LinkedHashMap` (the
backing storage) supports it. Bean/array/collection/class/enum descriptors keep
the original null check.
## Verification
- Added `testSerialize_MapWithNullKey` (round-trip test: map with a null key
serializes, deserializes, and preserves both key-value pairs)
- Existing `JavaBeanSerializeUtilTest` suite unaffected
## Checklist
- [x] I have read and agree to the Contributor Guidelines
- [x] I have added tests that prove my fix is effective
- [x] The PR targets the `3.3` branch
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]