docs(api): fix rich(...) lambda examples that render empty paragraphs - #537
Open
DemchaAV wants to merge 1 commit into
Open
docs(api): fix rich(...) lambda examples that render empty paragraphs#537DemchaAV wants to merge 1 commit into
DemchaAV wants to merge 1 commit into
Conversation
The Javadoc on ParagraphBuilder.rich(Consumer<RichText>) and
AbstractFlowBuilder.addRich(Consumer<RichText>) opened the lambda with
t.text("Status: ") — but RichText.text(String) is a static factory, and
Java resolves a static call made through an instance reference. The
documented line compiled, built a separate RichText, discarded it, and
the paragraph rendered empty: no warning, no exception.
Both examples now seed the supplied builder with plain(...); the factory
and class Javadoc spell out the trap; the shape-as-container recipe stops
calling RichText.of(), a factory that never existed; and a regression
test pins the documented lambda form to a non-empty paragraph.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
ParagraphBuilder.rich(Consumer<RichText>)andAbstractFlowBuilder.addRich(Consumer<RichText>)documented the lambda form ast -> t.text("Status: ").bold("Pending").RichText.text(String)is a static factory, and Java resolves a static call made through an instance reference — so the documented line compiles, builds a separateRichText, discards it, and the builder the consumer was handed stays empty. A reader copying the example gets a paragraph that renders no text at all: no compiler warning, no exception.The shape-as-container recipe carried a second rotted snippet, building its callout body with
RichText.of()— a factory that has never existed (git log --all -S 'static RichText of('comes back empty). It escapedDocumentationSnippetCompileTestbecause compile coverage underdocs/is opt-in per fence, and that fence references a baredocumentvariable, so it cannot be marked without scaffolding.Fix
plain(...)— the instance method that appends a plain run — and each Javadoc says whyt.text(...)must not be used there.RichText.text(String)'s own Javadoc spells out the trap, and the class Javadoc gains a correct lambda example next to the standalone-chain one, so every page a reader lands on tells the same story.docs/recipes/shape-as-container.mdbuilds the callout withRichText.text("Status: ").bold("Pending").text(String)was considered and rejected: Java forbids a static and an instance method with the same signature in one class (the pair cannot even coexist with the static deprecated), so it would mean deleting the 1.0.0-era static factory used across tests, examples and recipes — a source- and binary-breaking change on a patch line. A runtime "empty builder" guard inrich(Consumer)is also off the table: leaving the builder empty after conditional appends is a legitimate live pattern intemplates, so throwing would be a behaviour break.## v2.1.2 — Planned/### Documentation.A sweep of
core,templates,examples,docs/**and the local wiki found no call site hitting the trap — the broken pattern existed only in the two Javadoc examples, so no rendered output changes anywhere.Verification
./mvnw -B -ntp clean verify -pl :graph-compose-core,:graph-compose-render-pdf,:graph-compose-render-docx,:graph-compose-render-pptx,:graph-compose-templates,:graph-compose-testing,:graph-compose-qa,:graph-compose-coverage -amon the currentdevelophead → BUILD SUCCESS, all coverage checks met../mvnw -B -ntp javadoc:javadoc -pl :graph-compose-core→ BUILD SUCCESS. +1 test:RichTextTest.documentedRichLambdaSeededWithPlainProducesNonEmptyParagraphpins the documented lambda form to a non-empty, correctly-styled paragraph (RichTextTest26/26 green).Lane: canonical (
document.dslJavadoc + docs recipe + qa test) — no behaviour change, no public API change.