isaric commented on code in PR #4464:
URL: https://github.com/apache/solr/pull/4464#discussion_r3389015874
##########
solr/core/src/java/org/apache/solr/core/PluginInfo.java:
##########
@@ -193,26 +195,32 @@ public PluginInfo getChild(String type) {
@Override
@SuppressWarnings({"unchecked", "rawtypes"})
- public Map<String, Object> toMap(Map<String, Object> map) {
- map.putAll(attributes);
- Map m = map;
- if (initArgs != null) m.putAll(initArgs.asMap(3));
- if (children != null) {
- for (PluginInfo child : children) {
- Object old = m.get(child.name);
- if (old == null) {
- m.put(child.name, child.toMap(new LinkedHashMap<>()));
- } else if (old instanceof List list) {
- list.add(child.toMap(new LinkedHashMap<>()));
- } else {
- ArrayList l = new ArrayList();
- l.add(old);
- l.add(child.toMap(new LinkedHashMap<>()));
- m.put(child.name, l);
- }
+ public void writeMap(EntryWriter ew) throws IOException {
+ new NamedList<>(attributes).writeMap(ew);
Review Comment:
Had to walk this back in `11f40df6f5c` — sorry. The
`attributes.forEach(ew::putNoEx)` form fails at runtime with
`ClassCastException: LinkedHashMap cannot be cast to String`. Root cause:
`attributes` is declared `Map<String, String>`, but the `PluginInfo(String,
Map<String, Object>)` constructor assigns it via raw types
(`unmodifiableMap((LinkedHashMap) m)`), so values may be `LinkedHashMap`
(subcomponent payloads). The synthetic bridge the compiler generates for
`BiConsumer<String, String>` casts both args to `String`, which fails on those
values.
Restored `new NamedList<>(attributes).writeMap(ew);` — that constructor
iterates via `entrySet()` and stores everything as `Object` in its `nvPairs`
ArrayList, so no String-cast is generated. Added a comment so this isn't lost
again. Surfaces in `TestSolrConfigHandler.testReqHandlerAPIs` and
`testProperty`.
##########
solr/core/src/java/org/apache/solr/schema/IndexSchema.java:
##########
@@ -1699,7 +1698,7 @@ public Map<String, Object> toMap(Map<String, Object> map)
{
SchemaProps.Handler::getNameLower,
SchemaProps.Handler::getRealName));
public Map<String, Object> getNamedPropertyValues(String name, SolrParams
params) {
- return new SchemaProps(name, params, this).toMap(new LinkedHashMap<>());
+ return new SimpleOrderedMap<>(new SchemaProps(name, params, this));
Review Comment:
Had to walk this back in `11f40df6f5c` — sorry. Deep materialization via
`Utils.convertToMap` broke `SchemaXmlWriter.writeFieldTypes`: that method casts
nested values to `SimpleOrderedMap<Object>` (e.g. `analyzerProperties`,
`perFieldSimilarityProperties`). `Utils.convertToMap` recursively converts
every nested `MapWriter` (including `SimpleOrderedMap`, which implements
`MapWriter`) to a `LinkedHashMap`, breaking those downstream casts and causing
8 `TestSolrConfigHandler` failures on schema upgrade.
Restored `new SimpleOrderedMap<>(new SchemaProps(name, params, this));` (the
original Part 2 form). That does shallow conversion which preserves the inner
`SimpleOrderedMap` shape `SchemaXmlWriter` relies on. Added a comment to
explain the contract.
--
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]