[MAGNOLIA-6364] Map2Bean doesn't fail with wrong generic type Created: 07/Sep/15  Updated: 15/Apr/16  Resolved: 23/Sep/15

Status: Closed
Project: Magnolia
Component/s: None
Affects Version/s: 5.4.1
Fix Version/s: 5.4.3

Type: Bug Priority: Neutral
Reporter: Christoph Meier Assignee: Trang Truong
Resolution: Fixed Votes: 1
Labels: None
Remaining Estimate: 0d
Time Spent: 10d 7.5h
Original Estimate: 4.5h

Issue Links:
Relates
relates to MAGNOLIA-6386 App definitions downloaded as yaml re... Closed
relates to MAGNOLIA-6178 Add support for Map format in YAML fi... Closed
causality
is causing DOCU-617 NodeType Config in Yaml want's a coll... Closed
Template:
Acceptance criteria:
Empty
Task DoD:
[ ]* Doc/release notes changes? Comment present?
[ ]* Downstream builds green?
[ ]* Solution information and context easily available?
[ ]* Tests
[ ]* FixVersion filled and not yet released
[ ]  Architecture Decision Record (ADR)
Bug DoR:
[ ]* Steps to reproduce, expected, and actual results filled
[ ]* Affected version filled
Date of First Response:
Sprint: Basel 12
Story Points: 8

 Description   

Given the following *wrong* YAML fragment for a sample AvailabilityDefinition:

availability:
  nodeTypes:
    - mgnl-folder: mgnl:folder 

* The above is wrong because nodeTypes expects a list of strings, not maps.

When Map2BeanTransformer processes the "erroneous" YAML, It wrongly creates a collection containing maps, regardless of the generic type in the bean method signature.
Therefore, iterating over this collection will throw a ClassCastException.

Map2Bean should ignore entries which don't match the bean method's generic type, and warn accordingly.


See also

AvailabilityDefinition.java
Collection<String> getNodeTypes()


Side note #1:
The issue arose with a wrong YAML app descriptor, which was produced by the Download as YAML action.
See the corresponding JCR bootstrap file on git.

Side note #2:
Correct YAML fragment would be:

availability:
  nodeTypes:
    - mgnl:product


 Comments   
Comment by Mikaël Geljić [ 09/Sep/15 ]

FYI I eventually wrote a test-case demonstrating this issue. See branch bugfix/MAGNOLIA-6364-map2bean-generic-type-violation

Comment by Trang Truong [ 22/Sep/15 ]

mgeljic I investigated for the case of Correct YAML fragment and come up with 2 approaches

  • Before write to YAML file, in info.magnolia.config.converters.DefinitionRawViewToYamlConverterImpl.ConversionState#printProperty check if it's Collection of DefinitionRawView.Kind.Simple, print out only value of the item
    It's fixed cases of nodeTypes and roles list
  • Before it return list of properties info.magnolia.config.source.jcr.JcrConfigurationSource.DefinitionRawViewImpl#properties, we can re-process this list like we did at info.magnolia.config.source.raw.DefinitionRawViewMapWrapper#deriveValue.

Please could you give me advice on it? I committed my implementation to your above branch.

Comment by Aleksandr Pchelintcev [ 22/Sep/15 ]

MAGNOLIA-6178 is supposed to make Yaml config source to be lenient to the declarations like the current issue description (- mgnl-folder: mgnl:folder should be resolved correctly to a mere string). Though I'll double check of course.

After going through the changes - I agree with the statement of the ticket and with the changes that make mgeljic's test work (i.e. M2B skips the wrongly typed elements). However, this is a hypothetical situation. Whereas, the issues from the description of the ticket should be solved by MAGNOLIA-6178, a while ago I created a test case that should prove it: https://gist.github.com/p4elkin/34b5dccb5a7d9f8b7eaf (test name is crossConfigSourceConversionTest - needs some grooming and renaming probably, but shows the sense).

Anyway - I'm open for the discussion tmr, maybe I'm missing something.

Generated at Mon Feb 12 04:13:49 CET 2024 using Jira 9.4.2#940002-sha1:46d1a51de284217efdcb32434eab47a99af2938b.