Skip to content

Fix export of list attributes with custom Stapler converters#2789

Draft
somiljain2006 wants to merge 17 commits intojenkinsci:masterfrom
somiljain2006:List-converter-fix
Draft

Fix export of list attributes with custom Stapler converters#2789
somiljain2006 wants to merge 17 commits intojenkinsci:masterfrom
somiljain2006:List-converter-fix

Conversation

@somiljain2006
Copy link
Copy Markdown
Contributor

@somiljain2006 somiljain2006 commented Feb 20, 2026

Fix export of list attributes with custom Stapler converters by ensuring per-item conversion is applied during DataBoundConfigurator export, rather than passing collections directly to Stapler. This prevents incorrect mapping output and avoids argument type mismatches.

Fixes #2346

Your checklist for this pull request

🚨 Please review the guidelines for contributing to this repository.

  • Make sure you are requesting to pull a topic/feature/bugfix branch (right side) and not your master branch!
  • Ensure that the pull request title represents the desired changelog entry
  • Please describe what you did
  • Link to relevant issues in GitHub or in Jenkins JIRA
  • Link to relevant pull requests, esp. upstream and downstream changes
  • Did you provide a test case? That demonstrates a feature that works or fixes the issue.

@somiljain2006 somiljain2006 requested a review from a team as a code owner February 20, 2026 20:43
@timja timja added the bug label Feb 20, 2026
@timja
Copy link
Copy Markdown
Member

timja commented Feb 20, 2026

Approach looks rights but coverage is too low and tests need improving.

This will also need a run through the bom repo to see if it breaks any tests in other repositories.

@somiljain2006 somiljain2006 requested a review from timja February 21, 2026 13:50
@somiljain2006
Copy link
Copy Markdown
Contributor Author

@timja I’ve added additional tests to cover the supported collection and array export paths introduced by this change. Could you please take another look and let me know if the coverage is sufficient now?

@timja
Copy link
Copy Markdown
Member

timja commented Feb 21, 2026

@somiljain2006
Copy link
Copy Markdown
Contributor Author

@timja I’ve added tests covering the supported and intended scenarios for the new logic, including export and configuration of List, Set, and array, iteration over collection elements (including null entries).

The 28% coverage reported by CI seems to stem from the fact that the unreached lines are defensive fallbacks, which I haven't been able to trigger via standard testing.

Specifically, the completely uncovered lines (315-336, 340-346, 349) and partially covered branches (309-312, 339, 348, 350) exist to handle raw arrays or malformed data. However, due to strict YAML validation, it fails earlier and raises a ConfiguratorException before these paths can be reached. So, is there a way that is actually intended to hit these defensive branches, or how would you prefer I handle this unreachable code?

}

@SuppressWarnings("unused")
public static class StaplerConverterImpl implements Converter {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This converter doesn't seem to be doing anything, I deleted it and the tests still passed.

I would expect this to actually do something and have the tests rely on the behaviour.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That StaplerConverterImpl was a leftover from my earlier attempts to increase coverage. I have completely removed the unused converter in the latest commit.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't the whole point of this to have a customer converter though and demonstrate that it gets called for each item in the list rather than the list gets passed to it?

@somiljain2006 somiljain2006 requested a review from timja February 22, 2026 07:37
@timja
Copy link
Copy Markdown
Member

timja commented Feb 22, 2026

The 28% coverage reported by CI seems to stem from the fact that the unreached lines are defensive fallbacks, which I haven't been able to trigger via standard testing.

Specifically, the completely uncovered lines (315-336, 340-346, 349) and partially covered branches (309-312, 339, 348, 350) exist to handle raw arrays or malformed data. However, due to strict YAML validation, it fails earlier and raises a ConfiguratorException before these paths can be reached. So, is there a way that is actually intended to hit these defensive branches, or how would you prefer I handle this unreachable code?

Remove them then if they aren't reachable then they are misleading

Object converted;

if (a.isMultiple() && value instanceof Collection) {
List<Object> list = new ArrayList<>();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no coverage of this.

Can you please run the coverage locally?

mvnd clean verify jacoco:report -P enable-jacoco

# then
open plugin/target/site/jacoco/index.html

here's a screenshot of the current state:
image

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I'm working on adding tests to get those exact lines covered, and thanks for sharing that local coverage command that is going to make testing this locally much easier

@somiljain2006
Copy link
Copy Markdown
Contributor Author

I think there is something wrong with my logic because only if statements' conditions are being covered, not the inner logic, so I'm making this pr draft for a while till i came up with a new logic.

@somiljain2006 somiljain2006 marked this pull request as draft February 25, 2026 06:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

$StaplerConverterImpl is invoked with unexpected arguments

2 participants