Uploaded image for project: 'XWiki Rendering'
  1. XWiki Rendering
  2. XRENDERING-812

PrintTextListener duplicates the no-op listener callbacks of EmptyWemListener

    XMLWordPrintable

Details

    • Unknown
    • N/A
    • N/A

    Description

      Problem

      PrintTextListener implements IWemListener directly and redeclares 35 of the interface's callbacks with empty bodies, even though EmptyWemListener — another IWemListener implementation sitting in the same package — already provides exactly those empty implementations.

      As a result both classes carry the same run of identically-signed empty methods, in the same order. SonarCloud's copy-paste detector reports a 134-line duplicated block between them:

      • PrintTextListener lines 95-228
      • EmptyWemListener lines 76-197

      Consequence

      The duplication counts against the SonarCloud quality gate of org.xwiki.rendering:xwiki-rendering: the new_duplicated_lines_density condition reports 4.5% against a 3% threshold, so the gate is red. Every other condition passes.

      The duplication itself is long-standing; it only started counting once a comment-only change re-dated some of those lines into the new-code period.

      Proposal

      Make PrintTextListener extend EmptyWemListener and drop the no-op callbacks it then no longer needs to declare, so that the empty implementations live in one place only.

      Notes:

      • There is no user-visible change and no behaviour change.
      • beginDocument(WikiParameters) has to stay an explicit no-op override rather than being inherited: EmptyWemListener forwards it to the no-arg beginDocument(), which would start invoking a subclass override that previously was never called.
      • The change is binary compatible — the methods that stop being declared stay reachable through the new superclass, so code compiled against the previous version keeps loading and running. It does add EmptyWemListener as a supertype, which Revapi reports as java.class.nonFinalClassInheritsFromNewClass on the four affected classes, so it needs a justified ignore.

      Attachments

        Activity

          People

            vmassol Vincent Massol
            vmassol Vincent Massol
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: