Fix empty modified-lines REST API by making exported beans public - #786
Conversation
42e53db to
4d1905e
Compare
The modified-lines coverage REST API (.../coverage/modified/api/json) returns a response without the `files` array on recent Jenkins cores, even though the coverage data is computed and stored correctly. The classes backing the endpoint in the restapi package (ModifiedLinesCoverageApi, FileWithModifiedLines, ModifiedLinesBlock and the LineCoverageType enum) and their @exported getters were package-private. Recent Stapler releases only export @exported members that are public, so ModelBuilder finds zero exported properties and the `files` property is silently dropped. Older Stapler reflected non-public members, which is why this regressed on a core upgrade without any change to the plugin. Make the four types and their @exported accessors public, and add a serialization-level regression test that exercises the Stapler export layer (the existing endpoint integration test in GitForensicsITest is @disabled, so this path was untested). Fixes jenkinsci#785
4d1905e to
0aa9417
Compare
☀️ Quality MonitorTests Coverage for New Code 〰️ Line Coverage: 100.00% — perfect 🎉 Coverage for Whole Project 〰️ Line Coverage: 77.00% Style Bugs Vulnerabilities 🛡️ OWASP Dependency Check: 255 vulnerabilities Software Metrics 🌀 Cyclomatic Complexity: 1039 (total) 📌 Reference ResultsDelta reports computed against the reference results of 0181950 in workflow run 29743580601. 🚦 Quality GatesOverall Status: ✅ SUCCESS✅ Passed Gates
Created by Quality Monitor v4.15.0 (#82d77af). More details are shown in the GitHub Checks Result. |
The modified-lines coverage REST API (
.../coverage/modified/api/json) returns a responsewith no
filesarray on recent Jenkins cores, even though the coverage data is computedand stored correctly:
{"_class":"io.jenkins.plugins.coverage.metrics.restapi.ModifiedLinesCoverageApi"}Root cause: the classes backing this endpoint —
ModifiedLinesCoverageApi,FileWithModifiedLines,ModifiedLinesBlock, and theLineCoverageTypeenum — and their@Exportedgetters are package-private. Recent Stapler releases only export@Exportedmembers that are
public, soModelBuilderfinds zero exported properties and thefilesproperty is silently dropped. Older Stapler reflected non-public members, which iswhy this regressed on a Jenkins core upgrade without any change to the plugin:
filesin response1983.v93c53e94b_c042076.v1b_ac12445eb_eThe visibility was reduced in
cc8cdbd7("visibility changes in restapi package"); thedefect stayed latent until Stapler's behavior tightened.
Fix: make the four types and their
@Exportedaccessorspublic.Fixes #785
Testing done
Added
ModifiedLinesCoverageApiTest#shouldExportModifiedLinesAsJson, which serializes thebean through the same Stapler export path the endpoint uses (
ModelBuilder+Flavor.JSON) and asserts a non-emptyfilesarray. Verified it fails on thepackage-private code and passes with the visibility fix:
Different value found in node "files", expected: <array> but was: <missing>The existing integration test that exercises this endpoint
(
GitForensicsITest#verifyModifiedLinesCoverageApi) is currently@Disabled, so thispath had no active coverage — which is why the regression wasn't caught.
Also manually reproduced end-to-end: on Jenkins 2.555.3 with coverage
3.3278.va_04d3e352354, a build whose stored coverage data contains modified lines(confirmed via
filterByModifiedLines().getAllFileNodes()) returned an empty responsefrom
/coverage/modified/api/json; after installing a locally built plugin with this fix,the same build returned the fully populated
filesarray.Submitter checklist
not your main branch!
fixed